Example #1
0
func main() {
	c := cli.NewCLI(Name, Version)
	c.Args = os.Args[1:]
	c.Commands = map[string]cli.CommandFactory{
		"kontrol":         command.NewKontrol(),
		"vagrant":         command.NewVagrant(),
		"migrate":         command.NewMigrate(),
		"team":            command.NewTeam(),
		"group":           command.NewGroup(),
		"ping":            command.NewPing(),
		"event":           command.NewEvent(),
		"info":            command.NewInfo(),
		"build":           command.NewBuild(),
		"start":           command.NewCmd("start"),
		"stop":            command.NewCmd("stop"),
		"destroy":         command.NewCmd("destroy"),
		"restart":         command.NewCmd("restart"),
		"resize":          command.NewCmd("resize"),
		"reinit":          command.NewCmd("reinit"),
		"create-snapshot": command.NewCmd("createSnapshot"),
		"delete-snapshot": command.NewDeleteSnapshot(),
	}

	_, err := c.Run()
	if err != nil {
		command.DefaultUi.Error(err.Error())
	}
}
Example #2
0
func main() {
	if testCredentials() == false {
		fmt.Printf("CONSUMER_KEY and CONSUMER_SECRET need to be set!\n")
		return
	}

	anaconda.SetConsumerKey(CONSUMER_KEY)
	anaconda.SetConsumerSecret(CONSUMER_SECRET)
	initUi()

	c := cli.NewCLI("gogobird", "0.0.1")
	c.Args = os.Args[1:]
	c.Commands = map[string]cli.CommandFactory{
		"auth":      factoryAuth,
		"search":    factorySearch,
		"post":      factoryPost,
		"followers": factoryGetFollowers,
	}

	if len(c.Args) >= 1 && os.Args[1] != "auth" {
		if initTwitterApi() == false {
			ui.Error("init twitter api failed.")
			return
		}
	}

	exitStatus, err := c.Run()
	if err != nil {
		log.Println(err)
	}

	os.Exit(exitStatus)
}
Example #3
0
func doIt(ui cli.Ui, args []string) (int, error) {

	// special case `roster --list` and `roster --host hostname`.  I
	// tried doing this by making inventory the default command, but the
	// way that cli implemented you can't do '--host hostname', it tries
	// to make 'hostname' a subcommand and fails. See:
	// https://github.com/mitchellh/cli/issues/24
	//
	if (len(args) == 1 && args[0] == "--list") ||
		(len(args) == 2 && args[0] == "--host") {
		command, err := CmdInventoryFactory(ui)()
		if err != nil {
			return 1, err
		}
		return command.Run(args), nil
	}

	c := cli.NewCLI("roster", Version)
	c.Args = args
	c.Commands = map[string]cli.CommandFactory{
		"inventory":        CmdInventoryFactory(ui),
		"hosts":            CmdHostFactory(ui),
		"dump-template":    CmdDumpTemplateFactory(ui),
		"execute-template": CmdExecuteTemplateFactory(ui),
	}
	exitStatus, err := c.Run()
	return exitStatus, err
}
Example #4
0
func main() {
	stream.InitPlugins(
		[]stream.Plugin{
			&file.Plugin{},
			&s3.Plugin{},
			&http.Plugin{},
		})

	c := cli.NewCLI(appName, version)
	c.Args = os.Args[1:]
	c.Commands = map[string]cli.CommandFactory{
		"ls": func() (cli.Command, error) {
			return &stream.LSCommand{}, nil
		},
		"cp": func() (cli.Command, error) {
			return &stream.CopyCommand{}, nil
		},
		"cat": func() (cli.Command, error) {
			return &stream.CatCommand{}, nil
		},
	}

	status, err := c.Run()
	if err != nil {
		log.Println(err)
	}
	os.Exit(status)
}
Example #5
0
func main() {
	ui := &cli.BasicUi{Writer: os.Stdout}

	c := cli.NewCLI("kalash", "0.0.1")
	c.Args = os.Args[1:]
	c.Commands = map[string]cli.CommandFactory{
		"join": func() (cli.Command, error) {
			return JoinCommand{
				Ui:         ui,
				ShutdownCh: makeShutdownCh(),
			}, nil
		},
		"status": func() (cli.Command, error) {
			return StatusCommand{
				Ui: ui,
			}, nil
		},
		"leave": func() (cli.Command, error) {
			return LeaveCommand{
				Ui: ui,
			}, nil
		},
	}

	exitCode, err := c.Run()
	if err != nil {
		log.Println("Error executing CLI:", err)
		os.Exit(exitCode)
	}
}
Example #6
0
func main() {
	ui := &cli.BasicUi{
		Reader:      os.Stdin,
		Writer:      os.Stdout,
		ErrorWriter: os.Stderr,
	}

	c := cli.NewCLI("cli-multi-command-example", "0.0.1")
	c.Args = os.Args[1:]

	c.Commands = map[string]cli.CommandFactory{
		"ec2": func() (cli.Command, error) {
			return &ec2.EC2Command{Ui: ui}, nil
		},
		"s3": func() (cli.Command, error) {
			return &s3.S3Command{Ui: ui}, nil
		},
	}

	exitStatus, err := c.Run()
	if err != nil {
		fmt.Fprintln(os.Stderr, err.Error())
	}

	os.Exit(exitStatus)
}
Example #7
0
func main() {
	// コマンドの名前とバージョンを指定
	c := cli.NewCLI("iam-list", "1.0.0")

	// サブコマンドの引数を指定
	c.Args = os.Args[1:]

	// config読み込み
	cfg := Config{}
	config, err := cfg.LoadConfig("config.ini")
	raiseError(err)
	// TODO: オプションパラメータでファイル指定出来るように。

	// サブコマンド文字列 と コマンド実装の対応付け
	c.Commands = map[string]cli.CommandFactory{
		"group": func() (cli.Command, error) {
			return &Group{config: config}, nil
		},
		"user": func() (cli.Command, error) {
			return &User{config: config}, nil
		},
		"role": func() (cli.Command, error) {
			return &Role{config: config}, nil
		},
		// list-instance-profiles
	}

	// コマンド実行
	exitStatus, err := c.Run()
	if err != nil {
		log.Println(err)
	}

	os.Exit(exitStatus)
}
Example #8
0
func main() {
	AXAPI_VERSIONS := map[string]map[string]cli.CommandFactory{
		"v21": v21.Commands,
	}

	command := os.Args[0]
	args := os.Args[1:]

	// --version or -v to just show this cli tool version.
	for _, arg := range args {
		if arg == "-v" || arg == "--version" {
			fmt.Println(CLI_VERSION)
			os.Exit(0)
		}
	}

	// aXAPI version string must be specified.
	api_version := ""
	var command_map map[string]cli.CommandFactory
	if len(args) > 0 {
		for version, cmd_map := range AXAPI_VERSIONS {
			if args[0] == version {
				api_version = version
				command_map = cmd_map
				break
			}
		}
	}
	if api_version == "" {
		fmt.Println("You have to specify api version. try:")
		fmt.Printf("$ %v [API_VERSION] --help\n\n", command)
		fmt.Println("Available API_VERSIONs are:")
		for version, _ := range AXAPI_VERSIONS {
			fmt.Printf("   - %v\n", version)
		}
		os.Exit(0)
	}

	// --config-json to override default ConfigData
	configRe := regexp.MustCompile("--config-json=([^ ]+)")
	var configFilePath string
	for _, arg := range args {
		if group := configRe.FindStringSubmatch(arg); len(group) == 2 {
			configFilePath = group[1]
		}
	}
	config.ConfigInit(configFilePath)

	// run cli
	c := cli.NewCLI(command+" "+api_version, CLI_VERSION)
	c.Args = args[1:]
	c.Commands = command_map
	exitStatus, err := c.Run()
	if err != nil {
		log.Println(err)
	}
	os.Exit(exitStatus)
}
Example #9
0
func main() {
	// Get the command line args. We shortcut "--version" and "-v" to
	// just show the version.
	args := os.Args[1:]
	for _, arg := range args {
		if arg == "-v" || arg == "--version" {
			newArgs := make([]string, len(args)+1)
			newArgs[0] = "version"
			copy(newArgs[1:], args)
			args = newArgs
			break
		}
	}

	c := cli.NewCLI("dkron", VERSION)
	c.Args = args
	c.HelpFunc = cli.BasicHelpFunc("dkron")

	ui := &cli.BasicUi{Writer: os.Stdout}

	plugins := &Plugins{}
	plugins.DiscoverPlugins()

	// Make sure we clean up any managed plugins at the end of this
	defer plugin.CleanupClients()

	c.Commands = map[string]cli.CommandFactory{
		"agent": func() (cli.Command, error) {
			return &dkron.AgentCommand{
				Ui:               ui,
				Version:          VERSION,
				ProcessorPlugins: plugins.Processors,
			}, nil
		},
		"keygen": func() (cli.Command, error) {
			return &dkron.KeygenCommand{
				Ui: ui,
			}, nil
		},
		"version": func() (cli.Command, error) {
			return &dkron.VersionCommand{
				Version: VERSION,
				Ui:      ui,
			}, nil
		},
	}

	exitStatus, err := c.Run()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error executing CLI: %s\n", err.Error())
		os.Exit(1)
	}

	os.Exit(exitStatus)
}
Example #10
0
func main() {
	cli := cli.NewCLI("mirror", Version)
	cli.Args = os.Args[1:]
	cli.Commands = command.Commands

	exitStatus, err := cli.Run()
	if err != nil {
		fmt.Fprintln(os.Stderr, err.Error())
	}
	os.Exit(exitStatus)
}
Example #11
0
func main() {
	cli := cli.NewCLI(strings.ToLower(APPLICATION_NAME), VERSION)
	cli.Args = os.Args[1:]
	cli.Commands = command.Commands

	exitStatus, err := cli.Run()
	if err != nil {
		fmt.Fprintln(os.Stderr, err.Error())
	}

	os.Exit(exitStatus)
}
Example #12
0
func realMain() int {
	app := cli.NewCLI("vanguard", vanguard.Version)
	app.Args = os.Args[1:]
	app.Commands = Commands

	status, err := app.Run()
	if err != nil {
		fmt.Println(err)
		return 2
	}
	return status
}
Example #13
0
func main() {
	cli := cli.NewCLI("stack-deploy", "0.3.5.2")
	cli.Args = os.Args[1:]
	cli.Commands = commands()

	exitCode, err := cli.Run()
	if err != nil {
		fmt.Printf("Error exiting CLI: %s\n", err)
		os.Exit(1)
	}

	os.Exit(exitCode)
}
Example #14
0
func main() {
	c := cli.NewCLI("basetool", Version)
	c.Args = os.Args[1:]
	c.Commands = map[string]cli.CommandFactory{
		"get": GetCommandFactory,
	}

	exitStatus, err := c.Run()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error: %s\n", err)
	}
	os.Exit(exitStatus)
}
Example #15
0
func main() {

	ui := &cli.BasicUi{
		Reader:      os.Stdin,
		Writer:      os.Stdout,
		ErrorWriter: os.Stderr,
	}

	// CLI stuff
	c := cli.NewCLI("ec2-snapper", "1.0.0")
	c.Args = os.Args[1:]

	c.Commands = map[string]cli.CommandFactory{
		"create": func() (cli.Command, error) {
			return &CreateCommand{
				Ui: &cli.ColoredUi{
					Ui:          ui,
					OutputColor: cli.UiColorNone,
					ErrorColor:  cli.UiColorRed,
					WarnColor:   cli.UiColorYellow,
					InfoColor:   cli.UiColorGreen,
				},
			}, nil
		},
		"delete": func() (cli.Command, error) {
			return &DeleteCommand{
				Ui: &cli.ColoredUi{
					Ui:          ui,
					OutputColor: cli.UiColorNone,
					ErrorColor:  cli.UiColorRed,
					WarnColor:   cli.UiColorYellow,
					InfoColor:   cli.UiColorGreen,
				},
			}, nil
		},
	}

	// Confirm that AWS credentials are set as environment
	if os.Getenv("AWS_REGION") == "" {
		fmt.Println("ERROR: You must set the AWS_REGION environment variable to a value like \"us-west-2\" or \"us-east-1\"")
		os.Exit(1)
	}

	exitStatus, err := c.Run()
	if err != nil {
		fmt.Println(os.Stderr, err.Error())
	}

	os.Exit(exitStatus)

}
Example #16
0
File: main.go Project: yegle/fitbit
func main() {
	c := cli.NewCLI("fitbit", "0.0.1")
	c.Args = os.Args[1:]
	c.Commands = map[string]cli.CommandFactory{
		"login":   func() (cli.Command, error) { return LoginCommand{}, nil },
		"drink":   func() (cli.Command, error) { return DrinkCommand{}, nil },
		"profile": func() (cli.Command, error) { return ProfileCommand{}, nil },
	}
	if exitStatus, err := c.Run(); err != nil {
		log.Println(err)
	} else {
		os.Exit(exitStatus)
	}
}
Example #17
0
func main() {
	c := cli.NewCLI("ff", "0.0.3")
	c.Args = os.Args[1:]
	c.Commands = map[string]cli.CommandFactory{
		"provision-api": provisionCommandFactory,
		"playback-api":  playbackAPICommandFactory,
		"playback":      playbackCommandFactory,
	}

	exitStatus, err := c.Run()
	if err != nil {
		log.Println(err)
	}
	os.Exit(exitStatus)
}
Example #18
0
func main() {
	c := cli.NewCLI("cloudcompose", "1.0.0")
	c.Args = os.Args[1:]
	c.Commands = map[string]cli.CommandFactory{
		"validate": validatecommand.New,
		"push":     pushcommand.New,
	}

	exitStatus, err := c.Run()
	if err != nil {
		log.Println(err)
	}

	os.Exit(exitStatus)
}
Example #19
0
File: session.go Project: elos/elos
func (s *Session) run(args []string) {
	// construct a new CLI with name and version
	c := cli.NewCLI("elos", "0.1")
	c.Args = args
	ui := NewTextUI(s.input, s.Output)
	c.Commands = map[string]cli.CommandFactory{
		"habit": func() (cli.Command, error) {
			return &HabitCommand{
				UI:     ui,
				UserID: s.user.Id,
				DB:     s.db,
			}, nil
		},
		"people": func() (cli.Command, error) {
			return &PeopleCommand{
				UI:     ui,
				UserID: s.user.Id,
				DB:     s.db,
			}, nil
		},
		"tag": func() (cli.Command, error) {
			return &TagCommand{
				UI:     ui,
				UserID: s.user.Id,
				DB:     s.db,
			}, nil
		},
		"stream": func() (cli.Command, error) {
			return &StreamCommand{
				UI:     ui,
				UserID: s.user.Id,
				DB:     s.db,
			}, nil
		},
		"todo": func() (cli.Command, error) {
			return &TodoCommand{
				UI:     ui,
				UserID: s.user.Id,
				DB:     s.db,
			}, nil
		},
	}

	_, err := c.Run()
	if err != nil {
		log.Printf("command session error: %s", err)
	}
}
Example #20
0
func (cmd toolsCmd) Run(args []string) int {
	c := mcli.NewCLI("earthquake search tools", EarthquakeVersion)
	c.Args = args
	c.Commands = map[string]mcli.CommandFactory{
		"visualize":  tools.VisualizeCommandFactory,
		"dump-trace": tools.DumpTraceCommandFactory,
		"summary":    tools.SummaryCommandFactory,
	}

	exitStatus, err := c.Run()
	if err != nil {
		fmt.Printf("failed to execute search tool: %s\n", err)
	}

	return exitStatus
}
Example #21
0
File: main.go Project: naoty/sweep
func main() {
	c := cli.NewCLI("sweep", "0.1.0")
	c.Args = os.Args[1:]
	c.Commands = map[string]cli.CommandFactory{
		"": func() (cli.Command, error) {
			return &Sweep{}, nil
		},
	}

	exitStatus, err := c.Run()
	if err != nil {
		log.Println(err)
	}

	os.Exit(exitStatus)
}
Example #22
0
func Run() int {
	c := cli.NewCLI("ikafes", "1.0.0")
	c.Args = os.Args[1:]
	c.Commands = map[string]cli.CommandFactory{
		"status": func() (cli.Command, error) {
			return &Status{}, nil
		},
	}

	exitStatus, err := c.Run()
	if err != nil {
		log.Println(err)
	}

	return exitStatus
}
Example #23
0
func main() {
	c := cli.NewCLI("40fy-client", "1.0.0")
	c.Args = os.Args[1:]
	c.Commands = map[string]cli.CommandFactory{
		"stream":     StreamCommandFactory,
		"firehose":   FirehoseCommandFactory,
		"create-job": CreateJobCommandFactory,
	}

	exitStatus, err := c.Run()
	if err != nil {
		log.Println(err)
	}

	os.Exit(exitStatus)
}
Example #24
0
func (cmd inspectorsCmd) Run(args []string) int {
	c := mcli.NewCLI("earthquake inspectors", EarthquakeVersion)
	c.Args = args
	c.Commands = map[string]mcli.CommandFactory{
		"proc":     inspectors.ProcCommandFactory,
		"fs":       inspectors.FsCommandFactory,
		"ethernet": inspectors.EtherCommandFactory,
	}

	exitStatus, err := c.Run()
	if err != nil {
		fmt.Printf("failed to execute inspector: %s\n", err)
	}

	return exitStatus
}
Example #25
0
func main() {
	app := cli.NewCLI("cfval", Version)
	app.Args = os.Args[1:]
	app.Commands = map[string]cli.CommandFactory{
		"validate": func() (cli.Command, error) {
			return ValidateCommand{}, nil
		},
	}

	exitStatus, err := app.Run()
	if err != nil {
		log.Println(err)
	}

	os.Exit(exitStatus)
}
func main() {
	c := cli.NewCLI("goquilescvr", "0.0.1")

	c.Args = os.Args[1:]
	c.Commands = map[string]cli.CommandFactory{
		"start": startCommandFactory,
		"stop":  stopCommandFactory,
		"send":  sendCommandFactory,
	}

	exitStatus, err := c.Run()
	if err != nul {
		log.Println(err)
	}

	os.Exit(exitStatus)
}
Example #27
0
func main() {
	c := cli.NewCLI("earthquake", "0.1.2")
	c.Args = os.Args[1:]
	c.Commands = map[string]cli.CommandFactory{
		"tools": toolsCommandFactory,

		"init": initCommandFactory,
		"run":  runCommandFactory,
	}

	exitStatus, err := c.Run()
	if err != nil {
		fmt.Printf("failed to execute command: %s\n", err)
	}

	os.Exit(exitStatus)
}
Example #28
0
File: cli.go Project: rytmrt/difup
func Run(args []string) int {
	c := cli.NewCLI(COMMAND, VERSION)

	c.Args = args[0:]

	c.Commands = map[string]cli.CommandFactory{
		"deploy": func() (cli.Command, error) {
			return &cmd.Deploy{}, nil
		},
	}

	exitStatus, err := c.Run()
	if err != nil {
		log.Println(err)
	}

	return exitStatus
}
Example #29
0
File: nut.go Project: cfregly/Nut
func main() {
	c := cli.NewCLI("nut", version)
	c.Args = os.Args[1:]
	c.Commands = map[string]cli.CommandFactory{
		"archive": commands.Archive,
		"build":   commands.Build,
		"fetch":   commands.Fetch,
		"publish": commands.Publish,
		"restore": commands.Restore,
		"run":     commands.Run,
	}
	log.SetFormatter(&log.TextFormatter{FullTimestamp: true})
	exitStatus, err := c.Run()
	if err != nil {
		log.Errorln(err)
	}
	os.Exit(exitStatus)
}
Example #30
-2
// it all starts here
func main() {
	var c *cli.CLI // cli object
	var status int // exit status
	var err error  // general error holder

	// init and populate cli object
	c = cli.NewCLI(appName, appVersion)
	c.Args = os.Args[1:]     // arguments minus command
	c.Commands = cliCommands // see commands.go

	// run command and check return
	if status, err = c.Run(); err != nil {
		fmt.Fprintf(os.Stderr, "Error executing CLI: %s\n", err)
	}

	// exit
	os.Exit(status)
}