本文整理匯總了Golang中github.com/mitchellh/cli.NewCLI函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewCLI函數的具體用法?Golang NewCLI怎麽用?Golang NewCLI使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewCLI函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
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())
}
}
示例2: main
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)
}
示例3: doIt
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
}
示例4: main
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)
}
示例5: main
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)
}
}
示例6: main
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)
}
示例7: main
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)
}
示例8: main
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)
}
示例9: main
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)
}
示例10: main
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)
}
示例11: main
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)
}
示例12: realMain
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
}
示例13: main
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)
}
示例14: main
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)
}
示例15: main
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)
}