wip cli
This commit is contained in:
42
cmd/cli/commands/apply/apply.go
Normal file
42
cmd/cli/commands/apply/apply.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package apply
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"mirror-sync/pkg/project"
|
||||
"os"
|
||||
|
||||
"github.com/google/subcommands"
|
||||
)
|
||||
|
||||
type (
|
||||
ApplyCmd struct {
|
||||
}
|
||||
)
|
||||
|
||||
func (*ApplyCmd) Name() string { return "apply" }
|
||||
func (*ApplyCmd) Synopsis() string { return "apply the current project settings" }
|
||||
func (*ApplyCmd) Usage() string {
|
||||
return `Usage: git-sync apply
|
||||
|
||||
apply the current project settings
|
||||
|
||||
Options:
|
||||
`
|
||||
}
|
||||
|
||||
func (p *ApplyCmd) SetFlags(f *flag.FlagSet) {
|
||||
}
|
||||
|
||||
func (p *ApplyCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
|
||||
projectConfig, err := project.LoadCurrent()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error: %s\n", err)
|
||||
return subcommands.ExitFailure
|
||||
}
|
||||
|
||||
|
||||
|
||||
return subcommands.ExitSuccess
|
||||
}
|
||||
44
cmd/cli/commands/version/version.go
Normal file
44
cmd/cli/commands/version/version.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package version
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"mirror-sync/pkg/constants"
|
||||
"runtime"
|
||||
"strconv"
|
||||
|
||||
"github.com/google/subcommands"
|
||||
)
|
||||
|
||||
type (
|
||||
VersionCmd struct {
|
||||
}
|
||||
)
|
||||
|
||||
func (*VersionCmd) Name() string { return "version" }
|
||||
func (*VersionCmd) Synopsis() string { return "show version and system information" }
|
||||
func (*VersionCmd) Usage() string {
|
||||
return `Usage: cloudsave version
|
||||
|
||||
Print the version of the software
|
||||
|
||||
Options:
|
||||
`
|
||||
}
|
||||
|
||||
func (p *VersionCmd) SetFlags(f *flag.FlagSet) {
|
||||
}
|
||||
|
||||
func (p *VersionCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
|
||||
local()
|
||||
return subcommands.ExitSuccess
|
||||
}
|
||||
|
||||
func local() {
|
||||
fmt.Println("Client: git-sync cli")
|
||||
fmt.Println(" Version: " + constants.Version)
|
||||
fmt.Println(" API version: " + strconv.Itoa(constants.ApiVersion))
|
||||
fmt.Println(" Go version: " + runtime.Version())
|
||||
fmt.Println(" OS/Arch: " + runtime.GOOS + "/" + runtime.GOARCH)
|
||||
}
|
||||
25
cmd/cli/main.go
Normal file
25
cmd/cli/main.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"mirror-sync/cmd/cli/commands/apply"
|
||||
"mirror-sync/cmd/cli/commands/version"
|
||||
"os"
|
||||
|
||||
"github.com/google/subcommands"
|
||||
)
|
||||
|
||||
func main() {
|
||||
subcommands.Register(subcommands.HelpCommand(), "help")
|
||||
subcommands.Register(subcommands.FlagsCommand(), "help")
|
||||
subcommands.Register(subcommands.CommandsCommand(), "help")
|
||||
subcommands.Register(&version.VersionCmd{}, "help")
|
||||
|
||||
subcommands.Register(&apply.ApplyCmd{}, "projects")
|
||||
|
||||
flag.Parse()
|
||||
ctx := context.Background()
|
||||
|
||||
os.Exit(int(subcommands.Execute(ctx)))
|
||||
}
|
||||
Reference in New Issue
Block a user