Golang NewApp示例

说明

golang newapp示例是从最受好评的开源项目中提取的实现代码,你可以参考下面示例的使用方式。

编程语言: Golang

命名空间/包名称: github.com/codegangsta/cli

示例#1
文件: springboard_test.go 项目: draxil/springboard

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")
	}
}

示例#2
文件: command.go 项目: vnadgir-ef/vulcand

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)
}

示例#3
文件: main.go 项目: kunalkushwaha/libcompose

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)

}

示例#4
文件: main.go 项目: speedland/apps

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()
}

示例#5
文件: main.go 项目: wingolab/twobit

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: "[email protected]"}}
	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)
}

示例#6
文件: resize_test.go 项目: flazz/rack

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: ¶msResize{
			serverID: "server1",
		},
	}
	actual := &handler.Resource{
		Params: ¶msResize{},
	}
	err := cmd.HandleSingle(actual)
	th.AssertNoErr(t, err)
	th.AssertEquals(t, expected.Params.(*paramsResize).serverID, actual.Params.(*paramsResize).serverID)
}

示例#7
文件: artifacts_service.go 项目: hamfist/artifacts-service

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)
}

示例#8
文件: app.go 项目: pkdevbox/flint

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
}

示例#9
文件: init_updater.go 项目: hayatravis/goji_bbs_sample

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)
}

示例#10
文件: main.go 项目: JohnMurray/nbad

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)
}

示例#11
文件: cli.go 项目: hankerepo/volplugin

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)
}

示例#12
文件: cmd.go 项目: kgrvamsi/go-micro

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()
}

示例#13
文件: list_test.go 项目: flazz/rack

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: ¶msList{
			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)
}

示例#14
文件: snapd.go 项目: jcooklin/snap

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)
}

示例#15
文件: seaweed.go 项目: TomDeVito/seaweed-cli

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)
}

示例#16
文件: app_test.go 项目: CedarLogic/go-ethereum

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
}

示例#17
文件: util.go 项目: mattkanwisher/doit

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)
}

示例#18
文件: main.go 项目: speedland/service

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)
}

示例#19
文件: qunosy.go 项目: falsandtru/qunosy

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)
}

示例#20
文件: cli.go 项目: fbernardo/envman

// 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)
	}
}

示例#21
文件: main.go 项目: VoiSmart/grafana

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)
	}
}

示例#22
文件: app.go 项目: logdns/conoha-iso

func NewConoHaIso() *ConoHaIso {
	app := &ConoHaIso{
		App: cli.NewApp(),
	}
	app.setup()
	return app
}

示例#23
文件: main.go 项目: hasenbanck/wadoku2mongo

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: "[email protected]",
		},
	}

	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)
}

示例#24
文件: app_test.go 项目: CedarLogic/go-ethereum

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
}

示例#25
文件: main.go 项目: carnivalmobile/drone

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)
}

示例#26
文件: app_test.go 项目: CedarLogic/go-ethereum

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")
}

示例#27
文件: glide.go 项目: frozzare/glide

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)
}

示例#28
文件: app_test.go 项目: CedarLogic/go-ethereum

func TestApp_DefaultStdout(t *testing.T) {
	app := cli.NewApp()

	if app.Writer != os.Stdout {
		t.Error("Default output writer not set.")
	}
}

示例#29
文件: main.go 项目: gernest/apidemic

func main() {
	app := cli.NewApp()
	app.Name = "apidemic"
	app.Usage = "Fake JSON API Responses"
	app.Authors = []cli.Author{
		{"Geofrey Ernest", "[email protected]"},
	}
	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()
}

示例#30
文件: app_test.go 项目: CedarLogic/go-ethereum

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)
}

展开阅读全文