Esempio n. 1
0
func Test_glob_opts(t *testing.T) {
	{
		app := cli.NewApp()
		var our_wc watch.Config
		app.Flags = global_flags(&our_wc)
		is := make_is(t)
		app.Run([]string{""})
		is(our_wc.Debug, false, "debug off")
		is(our_wc.ProcessExistingFiles, false, "process existing off")
		is(our_wc.ReportErrors, true, "Error reportin on by default")
		is(our_wc.ReportActions, false, "Action reporting on by default")
		if our_wc.Paranoia != watch.NoParanoia {
			t.Fatal("unexpected paranoia")
		}
	}
	{
		app := cli.NewApp()
		var our_wc watch.Config
		app.Flags = global_flags(&our_wc)
		is := make_is(t)
		app.Run([]string{"", "--archive=FISHBOWL", "--error-dir=CATBASKET", "--debug", "--log-actions", "--log-errors=false", "--process-existing"})
		is(our_wc.ArchiveDir, "FISHBOWL", "archive dir")
		is(our_wc.ErrorDir, "CATBASKET", "error dir")
		is(our_wc.Debug, true, "debug on")
		is(our_wc.ReportActions, true, "action reporting on")
		is(our_wc.ReportErrors, false, "error reporting off")
		is(our_wc.ProcessExistingFiles, true, "process existing on")
	}
}
Esempio n. 2
0
func (cmd *Command) Run(args []string) error {
	url, args, err := findVulcanUrl(args)
	if err != nil {
		return err
	}
	cmd.vulcanUrl = url
	cmd.client = api.NewClient(cmd.vulcanUrl, cmd.registry)

	app := cli.NewApp()
	app.Name = "vctl"
	app.Usage = "Command line interface to a running vulcan instance"
	app.Flags = flags()

	app.Commands = []cli.Command{
		NewLogCommand(cmd),
		NewKeyCommand(cmd),
		NewTopCommand(cmd),
		NewHostCommand(cmd),
		NewBackendCommand(cmd),
		NewFrontendCommand(cmd),
		NewServerCommand(cmd),
		NewListenerCommand(cmd),
	}
	app.Commands = append(app.Commands, NewMiddlewareCommands(cmd)...)
	return app.Run(args)
}
Esempio n. 3
0
func main() {
	factory := &dockerApp.ProjectFactory{}

	app := cli.NewApp()
	app.Name = "libcompose-cli"
	app.Usage = "Command line interface for libcompose."
	app.Version = version.VERSION + " (" + version.GITCOMMIT + ")"
	app.Author = "Docker Compose Contributors"
	app.Email = "https://github.com/docker/libcompose"
	app.Before = cliApp.BeforeApp
	app.Flags = append(command.CommonFlags(), dockerApp.DockerClientFlags()...)
	app.Commands = []cli.Command{
		command.BuildCommand(factory),
		command.CreateCommand(factory),
		command.DownCommand(factory),
		command.KillCommand(factory),
		command.LogsCommand(factory),
		command.PauseCommand(factory),
		command.PortCommand(factory),
		command.PsCommand(factory),
		command.PullCommand(factory),
		command.RestartCommand(factory),
		command.RmCommand(factory),
		command.RunCommand(factory),
		command.ScaleCommand(factory),
		command.StartCommand(factory),
		command.StopCommand(factory),
		command.UnpauseCommand(factory),
		command.UpCommand(factory),
	}

	app.Run(os.Args)

}
Esempio n. 4
0
func main() {
	app := cli.NewApp()
	app.Name = "speedland-agent"
	app.Usage = "A agent command for speedland.net"
	app.Version = "1.0.0"
	app.Flags = []cli.Flag{
		cli.StringFlag{
			"config, c",
			"wcg.ini",
			"configuration file",
			"WCG_INI_FILE",
		},
	}
	app.Before = func(c *cli.Context) error {
		wcg.ConfigureProcess(c.String("config"))
		// normalize path
		lib.Config.Endpoint.Path = ""
		wcg.NewLogger(nil).Info("Used configurn file: %q", c.String("config"))
		wcg.NewLogger(nil).Info("Target Endpoint: %q", lib.Config.Endpoint)
		wcg.NewLogger(nil).Debug("Token: %q", lib.Config.Token)
		return nil
	}
	app.Commands = commands.AllCommands()
	app.Run(os.Args)
	wcg.WaitLogs()
}
Esempio n. 5
0
func main() {
	//p, _ := os.Create("twobit.cpuprofile")
	//pprof.StartCPUProfile(p)
	//defer pprof.StopCPUProfile()
	app := cli.NewApp()
	app.Name = "twobit"
	app.Authors = []cli.Author{cli.Author{Name: "Andrew E. Bruno", Email: "*****@*****.**"}}
	app.Usage = "Read/Write .2bit files"
	app.Version = "0.0.1"
	app.Commands = []cli.Command{
		{
			Name:  "convert",
			Usage: "Convert FASTA file to .2bit format.",
			Flags: []cli.Flag{
				&cli.BoolFlag{Name: "to-fasta, f", Usage: "Convert .2bit file to FASTA"},
				&cli.StringFlag{Name: "in, i", Usage: "Input file"},
				&cli.StringFlag{Name: "out, o", Usage: "Output file"},
			},
			Action: func(c *cli.Context) {
				if c.Bool("to-fasta") {
					ToFasta(c.String("in"), c.String("out"))
					return
				}

				To2bit(c.String("in"), c.String("out"))
			},
		},
	}

	app.Run(os.Args)
}
Esempio n. 6
0
func TestResizeHandleSingle(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	th.Mux.HandleFunc("/servers/detail", func(w http.ResponseWriter, r *http.Request) {
		w.Header().Add("Content-Type", "application/json")
		fmt.Fprintf(w, `{"servers":[{"ID":"server1","Name":"server1Name"}]}`)
	})
	app := cli.NewApp()
	flagset := flag.NewFlagSet("flags", 1)
	flagset.String("id", "", "")
	flagset.Set("id", "server1")
	c := cli.NewContext(app, flagset, nil)
	cmd := &commandResize{
		Ctx: &handler.Context{
			CLIContext:    c,
			ServiceClient: client.ServiceClient(),
		},
	}
	expected := &handler.Resource{
		Params: &paramsResize{
			serverID: "server1",
		},
	}
	actual := &handler.Resource{
		Params: &paramsResize{},
	}
	err := cmd.HandleSingle(actual)
	th.AssertNoErr(t, err)
	th.AssertEquals(t, expected.Params.(*paramsResize).serverID, actual.Params.(*paramsResize).serverID)
}
func main() {
	log := logrus.New()
	cli.VersionPrinter = func(c *cli.Context) {
		fmt.Printf("%s v=%s d=%s\n", c.App.Name, c.App.Version, GeneratedString)
	}

	app := cli.NewApp()
	app.Name = "artifacts-service"
	app.Version = VersionString
	app.Commands = []cli.Command{
		{
			Name:      "serve",
			ShortName: "s",
			Usage:     "run the HTTP thing",
			Action: func(_ *cli.Context) {
				server.Main(log)
			},
		},
		{
			Name:      "migrate",
			ShortName: "m",
			Usage:     "run database migrations",
			Action: func(_ *cli.Context) {
				server.MigratorMain(log)
			},
		},
	}

	app.Run(os.Args)
}
Esempio n. 8
0
func NewApp() *cli.App {
	app := cli.NewApp()
	app.Name = "flint"
	app.Usage = "Check a project for common sources of contributor friction"
	app.Version = "0.0.4"
	app.Flags = []cli.Flag{
		cli.BoolFlag{"skip-readme", "skip check for README", ""},
		cli.BoolFlag{"skip-contributing", "skip check for contributing guide", ""},
		cli.BoolFlag{"skip-license", "skip check for license", ""},
		cli.BoolFlag{"skip-bootstrap", "skip check for bootstrap script", ""},
		cli.BoolFlag{"skip-test-script", "skip check for test script", ""},
		cli.BoolFlag{"skip-scripts", "skip check for all scripts", ""},
		cli.BoolFlag{"no-color", "skip coloring the terminal output", ""},
		cli.StringFlag{
			Name:  "github, g",
			Value: "",
			Usage: "GitHub repository as owner/repo",
		},
		cli.StringFlag{
			Name:   "token, t",
			Value:  "",
			EnvVar: "FLINT_TOKEN",
			Usage:  "GitHub API access token",
		},
	}
	app.Action = func(c *cli.Context) {
		run(c)
	}

	return app
}
Esempio n. 9
0
func main() {
	app := cli.NewApp()
	app.Name = "initUpdater"
	app.Usage = "initUpdater is to init user table."
	app.Action = func(c *cli.Context) {
		/* -- DB -- */
		db, err := sql.Open("mysql", "root:@/test_bbs")
		if err != nil {
			panic(err.Error())
		}
		defer db.Close()

		/* -- SQL -- */
		sql_1 := "UPDATE user SET name = 'Paul', modified = NOW() WHERE id = 1;"
		data1, _ := db.Exec(sql_1)

		sql_2 := "UPDATE user SET name = 'John', modified = NOW() WHERE id = 2;"
		data2, _ := db.Exec(sql_2)

		println(data1)
		println(data2)
		println("initUdpater Finished!")
	}

	app.Run(os.Args)
}
Esempio n. 10
0
func main() {
	app := cli.NewApp()
	app.Name = "nbad"
	app.Usage = "NSCA Buffering Agent (daemon) - Emulates NSCA interface as local buffer/proxy"

	var configFile string
	var trace bool

	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:        "config, c",
			Value:       defaultConfLocation,
			Usage:       "Location of config file on disk",
			Destination: &configFile,
		},
		cli.BoolFlag{
			Name:        "trace, t",
			EnvVar:      "NBAD_TRACE",
			Usage:       "Turn on trace-logging",
			Destination: &trace,
		},
	}
	app.Version = "1.0"
	app.Action = func(c *cli.Context) {
		// load configuration
		InitConfig(configFile, TempLogger("STARTUP"))
		Config().TraceLogging = trace

		startServer()
	}
	app.Run(os.Args)
}
Esempio n. 11
0
func main() {
	app := cli.NewApp()
	app.Version = ""
	app.Usage = "Mount and manage Ceph RBD for containers"
	app.Flags = []cli.Flag{
		cli.BoolFlag{
			Name:   "debug",
			Usage:  "Turn on debug logging",
			EnvVar: "DEBUG",
		},
		cli.StringFlag{
			Name:   "master",
			Usage:  "Set the volmaster host:port",
			EnvVar: "MASTER",
			Value:  "localhost:8080",
		},
		cli.StringFlag{
			Name:   "host-label",
			Usage:  "Set the internal hostname",
			EnvVar: "HOSTLABEL",
			Value:  host,
		},
	}
	app.Action = run

	app.Run(os.Args)
}
Esempio n. 12
0
func Init() {
	cli.AppHelpTemplate = `
GLOBAL OPTIONS:
   {{range .Flags}}{{.}}
   {{end}}
`

	cli.HelpPrinter = func(writer io.Writer, templ string, data interface{}) {
		w := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0)
		t := template.Must(template.New("help").Parse(templ))
		err := t.Execute(w, data)
		if err != nil {
			panic(err)
		}
		w.Flush()
		os.Exit(2)
	}

	app := cli.NewApp()
	app.HideVersion = true
	app.Usage = "a go micro app"
	app.Action = func(c *cli.Context) {}
	app.Before = Setup
	app.Flags = Flags
	app.RunAndExitOnError()
}
Esempio n. 13
0
func TestListHandleFlags(t *testing.T) {
	app := cli.NewApp()
	flagset := flag.NewFlagSet("flags", 1)
	flagset.String("image", "", "")
	flagset.String("flavor", "", "")
	flagset.String("name", "", "")
	flagset.String("status", "", "")
	flagset.String("marker", "", "")
	flagset.Set("image", "13ba-75c0-4483-acf9")
	flagset.Set("flavor", "1234-b95f-ac5b-cd23")
	flagset.Set("name", "server*")
	flagset.Set("status", "AVAILABLE")
	flagset.Set("marker", "1fd3-4f9f-44df-1b5c")
	c := cli.NewContext(app, flagset, nil)
	cmd := &commandList{
		Ctx: &handler.Context{
			CLIContext: c,
		},
	}
	expected := &handler.Resource{
		Params: &paramsList{
			opts: &osServers.ListOpts{
				Image:  "13ba-75c0-4483-acf9",
				Flavor: "1234-b95f-ac5b-cd23",
				Name:   "server*",
				Status: "AVAILABLE",
				Marker: "1fd3-4f9f-44df-1b5c",
			},
		},
	}
	actual := &handler.Resource{}
	err := cmd.HandleFlags(actual)
	th.AssertNoErr(t, err)
	th.AssertDeepEquals(t, *expected.Params.(*paramsList).opts, *actual.Params.(*paramsList).opts)
}
Esempio n. 14
0
func main() {
	// Add a check to see if gitversion is blank from the build process
	if gitversion == "" {
		gitversion = "unknown"
	}

	app := cli.NewApp()
	app.Name = "snapd"
	app.Version = gitversion
	app.Usage = "A powerful telemetry framework"
	app.Flags = []cli.Flag{
		flAPIDisabled,
		flAPIPort,
		flAPIAddr,
		flLogLevel,
		flLogPath,
		flMaxProcs,
		flAutoDiscover,
		flNumberOfPLs,
		flCache,
		flPluginTrust,
		flKeyringPaths,
		flRestCert,
		flConfig,
		flRestHTTPS,
		flRestKey,
		flRestAuth,
	}
	app.Flags = append(app.Flags, scheduler.Flags...)
	app.Flags = append(app.Flags, tribe.Flags...)

	app.Action = action
	app.Run(os.Args)
}
Esempio n. 15
0
func main() {
	app := cli.NewApp()
	app.Name = "seaweed-cli"
	app.Usage = "Should I go surfing?"
	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:   "apiKey",
			Usage:  "Magic Seaweed API key",
			EnvVar: "MAGIC_SEAWEED_API_KEY",
		},
	}
	app.Commands = []cli.Command{
		{
			Name:        "forecast",
			Usage:       "forcast <spotId>",
			Description: "View the forecast for a spot",
			Action:      forecast,
		},
		{
			Name:        "today",
			Usage:       "today <spotId>",
			Description: "View today's forecast for a spot",
			Action:      today,
		},
		{
			Name:        "tomorrow",
			Usage:       "tomorrow <spotId>",
			Description: "View tomorrow's forecast for a spot",
			Action:      tomorrow,
		},
	}
	app.Run(os.Args)
}
Esempio n. 16
0
func ExampleAppHelp() {
	// set args for examples sake
	os.Args = []string{"greet", "h", "describeit"}

	app := cli.NewApp()
	app.Name = "greet"
	app.Flags = []cli.Flag{
		cli.StringFlag{Name: "name", Value: "bob", Usage: "a name to say"},
	}
	app.Commands = []cli.Command{
		{
			Name:        "describeit",
			Aliases:     []string{"d"},
			Usage:       "use it to see a description",
			Description: "This is how we describe describeit the function",
			Action: func(c *cli.Context) {
				fmt.Printf("i like to describe things")
			},
		},
	}
	app.Run(os.Args)
	// Output:
	// NAME:
	//    describeit - use it to see a description
	//
	// USAGE:
	//    command describeit [arguments...]
	//
	// DESCRIPTION:
	//    This is how we describe describeit the function
}
Esempio n. 17
0
func withinTest(cs Config, fs *flag.FlagSet, fn func(*cli.Context)) {
	ogSource := DefaultConfig
	DefaultConfig = cs

	defer func() {
		DefaultConfig = ogSource
	}()

	var b bytes.Buffer
	app := cli.NewApp()
	app.Writer = bufio.NewWriter(&b)

	globalSet := flag.NewFlagSet("global test", 0)
	globalSet.String("token", "token", "token")

	globalCtx := cli.NewContext(app, globalSet, nil)

	if fs == nil {
		fs = flag.NewFlagSet("local test", 0)
	}

	c := cli.NewContext(app, fs, globalCtx)

	fn(c)
}
Esempio n. 18
0
func main() {
	app := cli.NewApp()
	app.Name = "speedland-ng-agent: intern/pt"
	app.Version = lib.Commit
	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:   "config, c",
			Value:  "wcg.ini",
			Usage:  "configuration file",
			EnvVar: "WCG_INI_FILE",
		},
	}
	app.Before = func(c *cli.Context) error {
		agent.InitLog(c.String("config"))
		return nil
	}
	app.Action = func(c *cli.Context) {
		agent.RunAgent(
			async.NewRegularIntervalAgent(
				pt.NewAgent(agent.DefaultConfig.Endpoint.String(), agent.DefaultConfig.Token, nil),
				60*time.Second,
			),
		)
		wcg.WaitLogs()
	}
	app.Run(os.Args)
}
Esempio n. 19
0
func main() {
	app := cli.NewApp()
	app.Name = "qunosy"           // ヘルプを表示する際に使用される
	app.Usage = "print arguments" // ヘルプを表示する際に使用される
	app.Version = "0.1.0"         // ヘルプを表示する際に使用される
	absPath, _ := filepath.Abs("../qunosy")
	app.Action = func(c *cli.Context) { // コマンド実行時の処理
		if len(c.Args()) > 1 {
			if c.Args()[0] == "reload" {
				fmt.Println("Reloading qiita log ...")
				reload := exec.Command("sh", absPath+"/reload.sh", c.Args()[1])
				reloadOut, err := reload.Output()
				if err != nil {
					fmt.Println(err.Error())
					return
				}
				fmt.Print(string(reloadOut))
			} else {
				return
			}
		} else {
			qunosy := exec.Command("sh", absPath+"/qunosy.sh")
			qunosyOut, err := qunosy.Output()
			if err != nil {
				fmt.Println(err.Error())
				return
			}
			fmt.Print(string(qunosyOut))
		}
	}
	app.Run(os.Args)
}
Esempio n. 20
0
// Run the Envman CLI.
func Run() {
	// Read piped data
	if isPipedData() {
		if bytes, err := ioutil.ReadAll(os.Stdin); err != nil {
			log.Error("[ENVMAN] - Failed to read stdin:", err)
		} else if len(bytes) > 0 {
			stdinValue = string(bytes)
		}
	}

	// Parse cl
	cli.VersionPrinter = printVersion

	app := cli.NewApp()
	app.Name = path.Base(os.Args[0])
	app.Usage = "Environment variable manager"
	app.Version = "1.1.0"

	app.Author = ""
	app.Email = ""

	app.Before = before

	app.Flags = flags
	app.Commands = commands

	if err := app.Run(os.Args); err != nil {
		log.Fatal("[ENVMAN] - Finished:", err)
	}
}
Esempio n. 21
0
func main() {
	SetupLogging()

	app := cli.NewApp()
	app.Name = "Grafana cli"
	app.Usage = ""
	app.Author = "Grafana Project"
	app.Email = "https://github.com/grafana/grafana"
	app.Version = version
	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:   "pluginsDir",
			Usage:  "path to the grafana plugin directory",
			Value:  getGrafanaPluginDir(),
			EnvVar: "GF_PLUGIN_DIR",
		},
		cli.StringFlag{
			Name:   "repo",
			Usage:  "url to the plugin repository",
			Value:  "https://grafana.net/api/plugins",
			EnvVar: "GF_PLUGIN_REPO",
		},
		cli.BoolFlag{
			Name:  "debug, d",
			Usage: "enable debug logging",
		},
	}

	app.Commands = commands.Commands
	app.CommandNotFound = cmdNotFound

	if err := app.Run(os.Args); err != nil {
		log.Errorf("%v", err)
	}
}
Esempio n. 22
0
func NewConoHaIso() *ConoHaIso {
	app := &ConoHaIso{
		App: cli.NewApp(),
	}
	app.setup()
	return app
}
Esempio n. 23
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())

	app := cli.NewApp()
	app.Name = "wadoku2mongo"
	app.Usage = "Converts a wadoku XML dump into a mongodb collection"
	app.Version = "0.0.1"
	app.Authors = []cli.Author{
		cli.Author{
			Name:  "Nils Hasenbanck",
			Email: "*****@*****.**",
		},
	}

	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:  "file",
			Value: "data/wadoku.xml",
			Usage: "The path to the file of the wadoku XML dump",
		},
		cli.StringFlag{
			Name:  "mongodb",
			Value: "127.0.0.1",
			Usage: "The server connection string to the mongodb server",
		},
	}

	app.Action = func(c *cli.Context) {
		export(c.String("file"), c.String("mongodb"))
	}

	app.Run(os.Args)
}
Esempio n. 24
0
func ExampleAppBashComplete() {
	// set args for examples sake
	os.Args = []string{"greet", "--generate-bash-completion"}

	app := cli.NewApp()
	app.Name = "greet"
	app.EnableBashCompletion = true
	app.Commands = []cli.Command{
		{
			Name:        "describeit",
			Aliases:     []string{"d"},
			Usage:       "use it to see a description",
			Description: "This is how we describe describeit the function",
			Action: func(c *cli.Context) {
				fmt.Printf("i like to describe things")
			},
		}, {
			Name:        "next",
			Usage:       "next example",
			Description: "more stuff to see when generating bash completion",
			Action: func(c *cli.Context) {
				fmt.Printf("the next example")
			},
		},
	}

	app.Run(os.Args)
	// Output:
	// describeit
	// d
	// next
	// help
	// h
}
Esempio n. 25
0
func main() {
	app := cli.NewApp()
	app.Name = "drone"
	app.Version = version
	app.Usage = "command line utility"
	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:   "t, token",
			Value:  "",
			Usage:  "server auth token",
			EnvVar: "DRONE_TOKEN",
		},
		cli.StringFlag{
			Name:   "s, server",
			Value:  "",
			Usage:  "server location",
			EnvVar: "DRONE_SERVER",
		},
	}

	app.Commands = []cli.Command{
		NewBuildCommand(),
		NewReposCommand(),
		NewStatusCommand(),
		NewEnableCommand(),
		NewDisableCommand(),
		NewRestartCommand(),
		NewWhoamiCommand(),
	}

	app.Run(os.Args)
}
Esempio n. 26
0
func TestApp_RunAsSubcommandParseFlags(t *testing.T) {
	var context *cli.Context

	a := cli.NewApp()
	a.Commands = []cli.Command{
		{
			Name: "foo",
			Action: func(c *cli.Context) {
				context = c
			},
			Flags: []cli.Flag{
				cli.StringFlag{
					Name:  "lang",
					Value: "english",
					Usage: "language for the greeting",
				},
			},
			Before: func(_ *cli.Context) error { return nil },
		},
	}
	a.Run([]string{"", "foo", "--lang", "spanish", "abcd"})

	expect(t, context.Args().Get(0), "abcd")
	expect(t, context.String("lang"), "spanish")
}
Esempio n. 27
0
func main() {
	reg, router, cxt := cookoo.Cookoo()
	cxt.Put("VendorDir", VendorDir)

	routes(reg, cxt)

	app := cli.NewApp()
	app.Name = "glide"
	app.Usage = usage
	app.Version = version
	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:  "yaml, y",
			Value: "glide.yaml",
			Usage: "Set a YAML configuration file.",
		},
		cli.BoolFlag{
			Name:  "quiet, q",
			Usage: "Quiet (no info or debug messages)",
		},
	}
	app.CommandNotFound = func(c *cli.Context, command string) {
		cxt.Put("os.Args", os.Args)
		cxt.Put("command", command)
		setupHandler(c, "@plugin", cxt, router)
	}

	app.Commands = commands(cxt, router)

	app.Run(os.Args)
}
Esempio n. 28
0
func TestApp_DefaultStdout(t *testing.T) {
	app := cli.NewApp()

	if app.Writer != os.Stdout {
		t.Error("Default output writer not set.")
	}
}
Esempio n. 29
0
func main() {
	app := cli.NewApp()
	app.Name = "apidemic"
	app.Usage = "Fake JSON API Responses"
	app.Authors = []cli.Author{
		{"Geofrey Ernest", "*****@*****.**"},
	}
	app.Version = apidemic.Version
	app.Commands = []cli.Command{
		cli.Command{
			Name:      "start",
			ShortName: "s",
			Usage:     "starts apidemic server",
			Action:    server,
			Flags: []cli.Flag{
				cli.IntFlag{
					Name:   "port",
					Usage:  "http port to run",
					Value:  3000,
					EnvVar: "POSRT",
				},
			},
		},
	}
	app.RunAndExitOnError()
}
Esempio n. 30
0
func TestGlobalFlagsInSubcommands(t *testing.T) {
	subcommandRun := false
	app := cli.NewApp()

	app.Flags = []cli.Flag{
		cli.BoolFlag{Name: "debug, d", Usage: "Enable debugging"},
	}

	app.Commands = []cli.Command{
		cli.Command{
			Name: "foo",
			Subcommands: []cli.Command{
				{
					Name: "bar",
					Action: func(c *cli.Context) {
						if c.GlobalBool("debug") {
							subcommandRun = true
						}
					},
				},
			},
		},
	}

	app.Run([]string{"command", "-d", "foo", "bar"})

	expect(t, subcommandRun, true)
}