func Execute(name string, arguments []string) error { var err error env := bootstrap() defer func() { if err := env.Save(); err != nil { panic(err) } }() flags := flag.NewFlagSet(name, flag.ExitOnError) commands := []cli.Command{ { Name: "push", Description: "push changes (unidirectional)", Dispatcher: cli.CommandDispatchFunction(push.Execute), }, { Name: "repo", Description: "manage repositories", Dispatcher: cli.CommandDispatchFunction(repo.Execute), }, } usage := cli.Usage{ Usage: fmt.Sprintf("usage: %s [options] command [command options]", name), Description: "Sync data between local and remote repositories.", Flags: flags, Commands: commands, } flags.Usage = usage.Print showVersion := false flags.BoolVar(&showVersion, "version", false, "show program version") flags.Parse(arguments) if showVersion { fmt.Printf("csync version %s\n", env.Version()) return nil } err = cli.DispatchCommand(commands, flags.Args(), name) if _, ok := err.(cli.CommandDispatchError); ok && err != nil { fmt.Printf("ERROR: %v\n", err) usage.Print() os.Exit(1) } return err }
func Execute(name string, arguments []string) error { flags := flag.NewFlagSet(name, flag.ExitOnError) commands := []cli.Command{ { Name: "list", Description: "list repositories", }, { Name: "edit", Description: "edit repositories", }, { Name: "add", Description: "add an existing repository", }, { Name: "create", Description: "create a new repository", }, { Name: "remove", Description: "remove a repository", }, } usage := cli.Usage{ Usage: fmt.Sprintf("usage: %s [options] command [command options]", name), Description: "Manage csync repositories.", Flags: flags, Commands: commands, } flags.Usage = usage.Print flags.Parse(arguments) err := cli.DispatchCommand(usage.Commands, flags.Args(), name) if _, ok := err.(cli.CommandDispatchError); ok && err != nil { fmt.Printf("ERROR: %v\n", err) usage.Print() os.Exit(1) } return err }
func Execute(name string, arguments []string) error { flags := flag.NewFlagSet(name, flag.ExitOnError) usage := cli.Usage{ Usage: fmt.Sprintf("usage: %s [options] source_repo target_repo", name), Description: "Unidirectional sync between source_repo and target_repo.", Flags: flags, } flags.Usage = usage.Print flags.Parse(arguments) if flags.NArg() != 2 { usage.Print() os.Exit(1) } return push.Execute(push.Config{ SourceRepoId: flags.Arg(0), TargetRepoId: flags.Arg(1), }) }