本文整理汇总了Golang中github.com/mailgun/vulcand/Godeps/_workspace/src/github.com/codegangsta/cli.NewApp函数的典型用法代码示例。如果您正苦于以下问题:Golang NewApp函数的具体用法?Golang NewApp怎么用?Golang NewApp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewApp函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
log.InitWithConfig(log.Config{Name: "console"})
app := cli.NewApp()
app.Name = "vulcanbundle"
app.Usage = "Command line interface to compile plugins into vulcan binary"
app.Commands = []cli.Command{
{
Name: "init",
Usage: "Init bundle",
Action: initBundle,
Flags: []cli.Flag{
cli.StringSliceFlag{
Name: "middleware, m",
Value: &cli.StringSlice{},
Usage: "Path to repo and revision, e.g. github.com/mailgun/vulcand-plugins/auth",
},
},
},
}
err := app.Run(os.Args)
if err != nil {
log.Errorf("Error: %s\n", err)
}
}
示例2: TestApp_DefaultStdout
func TestApp_DefaultStdout(t *testing.T) {
app := cli.NewApp()
if app.Writer != os.Stdout {
t.Error("Default output writer not set.")
}
}
示例3: ExampleAppHelp
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",
ShortName: "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
}
示例4: TestGlobalFlagsInSubcommands
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)
}
示例5: ExampleAppBashComplete
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",
ShortName: "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
}
示例6: Example
func Example() {
app := cli.NewApp()
app.Name = "todo"
app.Usage = "task list on the command line"
app.Commands = []cli.Command{
{
Name: "add",
ShortName: "a",
Usage: "add a task to the list",
Action: func(c *cli.Context) {
println("added task: ", c.Args().First())
},
},
{
Name: "complete",
ShortName: "c",
Usage: "complete a task on the list",
Action: func(c *cli.Context) {
println("completed task: ", c.Args().First())
},
},
}
app.Run(os.Args)
}
示例7: TestNewCircuitBreakerFromCli
func (s *SpecSuite) TestNewCircuitBreakerFromCli(c *C) {
app := cli.NewApp()
app.Name = "test"
executed := false
app.Action = func(ctx *cli.Context) {
executed = true
out, err := FromCli(ctx)
c.Assert(out, NotNil)
c.Assert(err, IsNil)
cl := out.(*Spec)
c.Assert(cl.Condition, Equals, "LatencyAtQuantileMS(50.0) < 20")
c.Assert(cl.Fallback, Equals, `{"Type": "response", "Action": {"StatusCode": 400, "Body": "Come back later"}}`)
c.Assert(cl.OnTripped, Equals, `{"Type": "webhook", "Action": {"URL": "http://localhost", "Method": "GET"}}`)
c.Assert(cl.OnStandby, Equals, `{"Type": "webhook", "Action": {"URL": "http://localhost", "Method": "POST"}}`)
c.Assert(cl.FallbackDuration, Equals, 11*time.Second)
c.Assert(cl.RecoveryDuration, Equals, 12*time.Second)
c.Assert(cl.CheckPeriod, Equals, 14*time.Millisecond)
}
app.Flags = CliFlags()
app.Run([]string{"test",
"--condition=LatencyAtQuantileMS(50.0) < 20",
`--fallback={"Type": "response", "Action": {"StatusCode": 400, "Body": "Come back later"}}`,
`--onTripped={"Type": "webhook", "Action": {"URL": "http://localhost", "Method": "GET"}}`,
`--onStandby={"Type": "webhook", "Action": {"URL": "http://localhost", "Method": "POST"}}`,
`--fallbackDuration=11s`,
`--recoveryDuration=12s`,
`--checkPeriod=14ms`,
})
c.Assert(executed, Equals, true)
}
示例8: Run
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)
}
示例9: TestApp_ParseSliceFlags
func TestApp_ParseSliceFlags(t *testing.T) {
var parsedOption, firstArg string
var parsedIntSlice []int
var parsedStringSlice []string
app := cli.NewApp()
command := cli.Command{
Name: "cmd",
Flags: []cli.Flag{
cli.IntSliceFlag{Name: "p", Value: &cli.IntSlice{}, Usage: "set one or more ip addr"},
cli.StringSliceFlag{Name: "ip", Value: &cli.StringSlice{}, Usage: "set one or more ports to open"},
},
Action: func(c *cli.Context) {
parsedIntSlice = c.IntSlice("p")
parsedStringSlice = c.StringSlice("ip")
parsedOption = c.String("option")
firstArg = c.Args().First()
},
}
app.Commands = []cli.Command{command}
app.Run([]string{"", "cmd", "my-arg", "-p", "22", "-p", "80", "-ip", "8.8.8.8", "-ip", "8.8.4.4"})
IntsEquals := func(a, b []int) bool {
if len(a) != len(b) {
return false
}
for i, v := range a {
if v != b[i] {
return false
}
}
return true
}
StrsEquals := func(a, b []string) bool {
if len(a) != len(b) {
return false
}
for i, v := range a {
if v != b[i] {
return false
}
}
return true
}
var expectedIntSlice = []int{22, 80}
var expectedStringSlice = []string{"8.8.8.8", "8.8.4.4"}
if !IntsEquals(parsedIntSlice, expectedIntSlice) {
t.Errorf("%v does not match %v", parsedIntSlice, expectedIntSlice)
}
if !StrsEquals(parsedStringSlice, expectedStringSlice) {
t.Errorf("%v does not match %v", parsedStringSlice, expectedStringSlice)
}
}
示例10: TestApp_Command
func TestApp_Command(t *testing.T) {
app := cli.NewApp()
fooCommand := cli.Command{Name: "foobar", ShortName: "f"}
batCommand := cli.Command{Name: "batbaz", ShortName: "b"}
app.Commands = []cli.Command{
fooCommand,
batCommand,
}
for _, test := range commandAppTests {
expect(t, app.Command(test.name) != nil, test.expected)
}
}
示例11: TestApp_Run
func TestApp_Run(t *testing.T) {
s := ""
app := cli.NewApp()
app.Action = func(c *cli.Context) {
s = s + c.Args().First()
}
err := app.Run([]string{"command", "foo"})
expect(t, err, nil)
err = app.Run([]string{"command", "bar"})
expect(t, err, nil)
expect(t, s, "foobar")
}
示例12: TestApp_Float64Flag
func TestApp_Float64Flag(t *testing.T) {
var meters float64
app := cli.NewApp()
app.Flags = []cli.Flag{
cli.Float64Flag{Name: "height", Value: 1.5, Usage: "Set the height, in meters"},
}
app.Action = func(c *cli.Context) {
meters = c.Float64("height")
}
app.Run([]string{"", "--height", "1.93"})
expect(t, meters, 1.93)
}
示例13: TestAppNoHelpFlag
func TestAppNoHelpFlag(t *testing.T) {
oldFlag := cli.HelpFlag
defer func() {
cli.HelpFlag = oldFlag
}()
cli.HelpFlag = cli.BoolFlag{}
app := cli.NewApp()
err := app.Run([]string{"test", "-h"})
if err != flag.ErrHelp {
t.Errorf("expected error about missing help flag, but got: %s (%T)", err, err)
}
}
示例14: ExampleApp
func ExampleApp() {
// set args for examples sake
os.Args = []string{"greet", "--name", "Jeremy"}
app := cli.NewApp()
app.Name = "greet"
app.Flags = []cli.Flag{
cli.StringFlag{Name: "name", Value: "bob", Usage: "a name to say"},
}
app.Action = func(c *cli.Context) {
fmt.Printf("Hello %v\n", c.String("name"))
}
app.Run(os.Args)
// Output:
// Hello Jeremy
}
示例15: TestSecureFromCli
func (s *SecureSuite) TestSecureFromCli(c *C) {
app := cli.NewApp()
app.Name = "secure_test"
executed := false
app.Action = func(ctx *cli.Context) {
executed = true
out, err := FromCli(ctx)
c.Assert(out, NotNil)
c.Assert(err, IsNil)
m := out.(*SecureMiddleware)
c.Assert(m.Opts.BrowserXssFilter, Equals, true)
}
app.Flags = CliFlags()
app.Run([]string{"secure_test", "--xss-filter"})
c.Assert(executed, Equals, true)
}