wip
This commit is contained in:
@@ -4,15 +4,18 @@ import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"mirror-sync/cmd/cli/config"
|
||||
"mirror-sync/pkg/client"
|
||||
"mirror-sync/pkg/project"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/google/subcommands"
|
||||
)
|
||||
|
||||
type (
|
||||
ApplyCmd struct {
|
||||
projectName string
|
||||
}
|
||||
)
|
||||
|
||||
@@ -28,10 +31,22 @@ Options:
|
||||
}
|
||||
|
||||
func (p *ApplyCmd) SetFlags(f *flag.FlagSet) {
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
f.StringVar(&p.projectName, "project-name", filepath.Base(wd), "set the project name")
|
||||
}
|
||||
|
||||
func (p *ApplyCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
|
||||
projectConfig, err := project.LoadCurrent()
|
||||
clientConfig := config.Load()
|
||||
|
||||
defaultValues := project.DefaultValues{
|
||||
DaemonURL: clientConfig.Deamon.URL,
|
||||
ProjectName: p.projectName,
|
||||
}
|
||||
|
||||
projectConfig, err := project.LoadCurrent(defaultValues)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error: %s\n", err)
|
||||
return subcommands.ExitFailure
|
||||
|
||||
@@ -56,6 +56,6 @@ func print(pr project.Project) {
|
||||
fmt.Println("------------------")
|
||||
|
||||
for _, repo := range pr.Repositories {
|
||||
fmt.Printf("%-20s | %s -> %s | %s\n", repo.Name, repo.Source, repo.Destination, repo.Schedule)
|
||||
fmt.Printf("%s | %-20s | %s -> %s | %s\n", repo.UUID, repo.Name, repo.Source, repo.Destination, repo.Schedule)
|
||||
}
|
||||
}
|
||||
|
||||
60
cmd/cli/commands/remove/remove.go
Normal file
60
cmd/cli/commands/remove/remove.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package remove
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"mirror-sync/cmd/cli/config"
|
||||
"mirror-sync/pkg/client"
|
||||
"mirror-sync/pkg/project"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/google/subcommands"
|
||||
)
|
||||
|
||||
type (
|
||||
DownCmd struct {
|
||||
projectName string
|
||||
}
|
||||
)
|
||||
|
||||
func (*DownCmd) Name() string { return "down" }
|
||||
func (*DownCmd) Synopsis() string { return "remove the current project schedule" }
|
||||
func (*DownCmd) Usage() string {
|
||||
return `Usage: mirror-sync down
|
||||
|
||||
remove the current project
|
||||
`
|
||||
}
|
||||
|
||||
func (p *DownCmd) SetFlags(f *flag.FlagSet) {
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
f.StringVar(&p.projectName, "project-name", filepath.Base(wd), "set the project name")
|
||||
}
|
||||
|
||||
func (p *DownCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
|
||||
clientConfig := config.Load()
|
||||
|
||||
defaultValues := project.DefaultValues{
|
||||
DaemonURL: clientConfig.Deamon.URL,
|
||||
ProjectName: p.projectName,
|
||||
}
|
||||
|
||||
projectConfig, err := project.LoadCurrent(defaultValues)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error: %s\n", err)
|
||||
return subcommands.ExitFailure
|
||||
}
|
||||
|
||||
cli := client.New(projectConfig.ServerURL)
|
||||
if err := cli.Remove(projectConfig); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error: %s\n", err)
|
||||
return subcommands.ExitFailure
|
||||
}
|
||||
|
||||
return subcommands.ExitSuccess
|
||||
}
|
||||
60
cmd/cli/commands/run/run.go
Normal file
60
cmd/cli/commands/run/run.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package run
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"mirror-sync/cmd/cli/config"
|
||||
"mirror-sync/pkg/client"
|
||||
"mirror-sync/pkg/project"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/google/subcommands"
|
||||
)
|
||||
|
||||
type (
|
||||
RunCmd struct {
|
||||
}
|
||||
)
|
||||
|
||||
func (*RunCmd) Name() string { return "run" }
|
||||
func (*RunCmd) Synopsis() string { return "run the current project schedule" }
|
||||
func (*RunCmd) Usage() string {
|
||||
return `Usage: mirror-sync run
|
||||
|
||||
run the current project
|
||||
`
|
||||
}
|
||||
|
||||
func (p *RunCmd) SetFlags(f *flag.FlagSet) {
|
||||
}
|
||||
|
||||
func (p *RunCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
|
||||
clientConfig := config.Load()
|
||||
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error: %s\n", err)
|
||||
return subcommands.ExitFailure
|
||||
}
|
||||
|
||||
defaultValues := project.DefaultValues{
|
||||
DaemonURL: clientConfig.Deamon.URL,
|
||||
ProjectName: filepath.Base(wd),
|
||||
}
|
||||
|
||||
projectConfig, err := project.LoadCurrent(defaultValues)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error: %s\n", err)
|
||||
return subcommands.ExitFailure
|
||||
}
|
||||
|
||||
cli := client.New(projectConfig.ServerURL)
|
||||
if err := cli.RunOne(projectConfig); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error: %s\n", err)
|
||||
return subcommands.ExitFailure
|
||||
}
|
||||
|
||||
return subcommands.ExitSuccess
|
||||
}
|
||||
@@ -4,7 +4,10 @@ import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"mirror-sync/cmd/cli/config"
|
||||
"mirror-sync/pkg/client"
|
||||
"mirror-sync/pkg/constants"
|
||||
"os"
|
||||
"runtime"
|
||||
"strconv"
|
||||
|
||||
@@ -31,14 +34,31 @@ 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: mirror-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)
|
||||
|
||||
clientConfig := config.Load()
|
||||
|
||||
cli := client.New(clientConfig.Deamon.URL)
|
||||
systemInfoDaemon, err := cli.Version()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error: %s\n", err)
|
||||
return subcommands.ExitFailure
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
fmt.Println("Daemon:")
|
||||
fmt.Println(" Version: " + systemInfoDaemon.Version)
|
||||
fmt.Println(" API version: " + strconv.Itoa(systemInfoDaemon.APIVersion))
|
||||
fmt.Println(" Go version: " + systemInfoDaemon.GoVersion)
|
||||
fmt.Println(" OS/Arch: " + systemInfoDaemon.OSName + "/" + systemInfoDaemon.OSArchitecture)
|
||||
|
||||
return subcommands.ExitSuccess
|
||||
}
|
||||
|
||||
func local() {
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user