本文整理汇总了Golang中github.com/rackspace/rack/internal/github.com/codegangsta/cli.NewApp函数的典型用法代码示例。如果您正苦于以下问题:Golang NewApp函数的具体用法?Golang NewApp怎么用?Golang NewApp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewApp函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestApp_ParseSliceFlagsWithMissingValue
func TestApp_ParseSliceFlagsWithMissingValue(t *testing.T) {
var parsedIntSlice []int
var parsedStringSlice []string
app := cli.NewApp()
command := cli.Command{
Name: "cmd",
Flags: []cli.Flag{
cli.IntSliceFlag{Name: "a", Usage: "set numbers"},
cli.StringSliceFlag{Name: "str", Usage: "set strings"},
},
Action: func(c *cli.Context) {
parsedIntSlice = c.IntSlice("a")
parsedStringSlice = c.StringSlice("str")
},
}
app.Commands = []cli.Command{command}
app.Run([]string{"", "cmd", "my-arg", "-a", "2", "-str", "A"})
var expectedIntSlice = []int{2}
var expectedStringSlice = []string{"A"}
if parsedIntSlice[0] != expectedIntSlice[0] {
t.Errorf("%v does not match %v", parsedIntSlice[0], expectedIntSlice[0])
}
if parsedStringSlice[0] != expectedStringSlice[0] {
t.Errorf("%v does not match %v", parsedIntSlice[0], expectedIntSlice[0])
}
}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:31,代码来源:app_test.go
示例2: TestListHandleSingle
func TestListHandleSingle(t *testing.T) {
app := cli.NewApp()
flagset := flag.NewFlagSet("flags", 1)
flagset.String("stack-name", "", "")
flagset.String("stack-id", "", "")
flagset.Set("stack-name", "stack1")
flagset.Set("stack-id", "id1")
c := cli.NewContext(app, flagset, nil)
cmd := &commandList{
Ctx: &handler.Context{
CLIContext: c,
},
}
expected := &handler.Resource{
Params: ¶msList{
stackName: "stack1",
stackID: "id1",
},
}
actual := &handler.Resource{
Params: ¶msList{},
}
err := cmd.HandleSingle(actual)
th.AssertNoErr(t, err)
th.AssertEquals(t, expected.Params.(*paramsList).stackName, actual.Params.(*paramsList).stackName)
th.AssertEquals(t, expected.Params.(*paramsList).stackID, actual.Params.(*paramsList).stackID)
}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:28,代码来源:list_test.go
示例3: TestGenerateExecute
func TestGenerateExecute(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/os-keypairs", func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/json")
fmt.Fprintf(w, `{"keypair":{}}`)
})
app := cli.NewApp()
flagset := flag.NewFlagSet("flags", 1)
flagset.String("output", "json", "")
c := cli.NewContext(app, flagset, nil)
cmd := &commandGenerate{
Ctx: &handler.Context{
CLIContext: c,
ServiceClient: client.ServiceClient(),
},
}
actual := &handler.Resource{
Params: ¶msGenerate{
opts: &osKeypairs.CreateOpts{
Name: "keypair1Name",
},
},
}
cmd.Execute(actual)
th.AssertNoErr(t, actual.Err)
}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:27,代码来源:generate_test.go
示例4: TestCreateHandleFlags
func TestCreateHandleFlags(t *testing.T) {
app := cli.NewApp()
flagset := flag.NewFlagSet("flags", 1)
flagset.String("metadata", "", "")
flagset.String("container-read", "", "")
flagset.String("container-write", "", "")
flagset.Set("metadata", "key=val,foo=bar")
c := cli.NewContext(app, flagset, nil)
cmd := &commandCreate{
Ctx: &handler.Context{
CLIContext: c,
},
}
expected := &handler.Resource{
Params: ¶msCreate{
opts: containers.CreateOpts{
Metadata: map[string]string{
"key": "val",
"foo": "bar",
},
},
},
}
actual := &handler.Resource{}
err := cmd.HandleFlags(actual)
th.AssertNoErr(t, err)
th.AssertDeepEquals(t, expected.Params.(*paramsCreate).opts, actual.Params.(*paramsCreate).opts)
}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:28,代码来源:create_test.go
示例5: TestApp_DefaultStdout
func TestApp_DefaultStdout(t *testing.T) {
app := cli.NewApp()
if app.Writer != os.Stdout {
t.Error("Default output writer not set.")
}
}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:7,代码来源:app_test.go
示例6: Example
func Example() {
app := cli.NewApp()
app.Name = "todo"
app.Usage = "task list on the command line"
app.Commands = []cli.Command{
{
Name: "add",
Aliases: []string{"a"},
Usage: "add a task to the list",
Action: func(c *cli.Context) {
println("added task: ", c.Args().First())
},
},
{
Name: "complete",
Aliases: []string{"c"},
Usage: "complete a task on the list",
Action: func(c *cli.Context) {
println("completed task: ", c.Args().First())
},
},
}
app.Run(os.Args)
}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:25,代码来源:cli_test.go
示例7: 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",
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
}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:34,代码来源:app_test.go
示例8: TestListHandleFlags
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)
}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:35,代码来源:list_test.go
示例9: TestUploadHandleFlags
func TestUploadHandleFlags(t *testing.T) {
app := cli.NewApp()
flagset := flag.NewFlagSet("flags", 1)
flagset.String("name", "", "")
flagset.String("file", "", "")
flagset.String("public-key", "", "")
flagset.Set("name", "keypair1Name")
flagset.Set("public-key", "ssh public key data here")
c := cli.NewContext(app, flagset, nil)
cmd := &commandUpload{
Ctx: &handler.Context{
CLIContext: c,
},
}
expected := &handler.Resource{
Params: ¶msUpload{
opts: &osKeypairs.CreateOpts{
Name: "keypair1Name",
PublicKey: "ssh public key data here",
},
},
}
actual := &handler.Resource{}
err := cmd.HandleFlags(actual)
th.AssertNoErr(t, err)
th.AssertDeepEquals(t, *expected.Params.(*paramsUpload).opts, *actual.Params.(*paramsUpload).opts)
}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:27,代码来源:upload_test.go
示例10: TestCreateHandleSingle
func TestCreateHandleSingle(t *testing.T) {
app := cli.NewApp()
flagset := flag.NewFlagSet("flags", 1)
flagset.String("name", "", "")
flagset.Set("name", "server1")
c := cli.NewContext(app, flagset, nil)
cmd := &commandCreate{
Ctx: &handler.Context{
CLIContext: c,
},
}
expected := &handler.Resource{
Params: ¶msCreate{
opts: &servers.CreateOpts{
Name: "server1",
},
},
}
actual := &handler.Resource{
Params: ¶msCreate{
opts: &servers.CreateOpts{},
},
}
err := cmd.HandleSingle(actual)
th.AssertNoErr(t, err)
th.AssertEquals(t, expected.Params.(*paramsCreate).opts.Name, actual.Params.(*paramsCreate).opts.Name)
}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:27,代码来源:create_test.go
示例11: TestListHandleFlags
func TestListHandleFlags(t *testing.T) {
app := cli.NewApp()
flagset := flag.NewFlagSet("flags", 1)
flagset.String("sort-dir", "", "")
flagset.String("sort-key", "", "")
flagset.String("name", "", "")
flagset.String("status", "", "")
flagset.String("marker", "", "")
flagset.Set("sort-dir", "asc")
flagset.Set("sort-key", "name")
flagset.Set("name", "stacks*")
flagset.Set("status", "CREATE_COMPLETE")
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: &osStacks.ListOpts{
SortKey: "name",
SortDir: "asc",
Name: "stacks*",
Status: "CREATE_COMPLETE",
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)
}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:35,代码来源:list_test.go
示例12: TestApp_Run_Version
func TestApp_Run_Version(t *testing.T) {
var versionArguments = [][]string{{"boom", "--version"}, {"boom", "-v"}}
for _, args := range versionArguments {
buf := new(bytes.Buffer)
t.Logf("==> checking with arguments %v", args)
app := cli.NewApp()
app.Name = "boom"
app.Usage = "make an explosive entrance"
app.Version = "0.1.0"
app.Writer = buf
app.Action = func(c *cli.Context) {
buf.WriteString("boom I say!")
}
err := app.Run(args)
if err != nil {
t.Error(err)
}
output := buf.String()
t.Logf("output: %q\n", buf.Bytes())
if !strings.Contains(output, "0.1.0") {
t.Errorf("want version to contain %q, did not: \n%q", "0.1.0", output)
}
}
}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:30,代码来源:app_test.go
示例13: TestRebootHandleSingle
func TestRebootHandleSingle(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("name", "", "")
flagset.Set("name", "server1Name")
c := cli.NewContext(app, flagset, nil)
cmd := &commandReboot{
Ctx: &handler.Context{
CLIContext: c,
ServiceClient: client.ServiceClient(),
},
}
expected := &handler.Resource{
Params: ¶msReboot{
serverID: "server1",
},
}
actual := &handler.Resource{
Params: ¶msReboot{},
}
err := cmd.HandleSingle(actual)
th.AssertNoErr(t, err)
th.AssertEquals(t, expected.Params.(*paramsReboot).serverID, actual.Params.(*paramsReboot).serverID)
}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:30,代码来源:reboot_test.go
示例14: TestDeleteExecute
func TestDeleteExecute(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/container1", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNoContent)
})
app := cli.NewApp()
flagset := flag.NewFlagSet("flags", 1)
flagset.String("name", "", "")
flagset.Set("name", "container1")
c := cli.NewContext(app, flagset, nil)
cmd := &commandDelete{
Ctx: &handler.Context{
ServiceClient: client.ServiceClient(),
CLIContext: c,
},
}
actual := &handler.Resource{
Params: ¶msDelete{
container: "container1",
},
}
cmd.Execute(actual)
th.AssertNoErr(t, actual.Err)
}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:25,代码来源:delete_test.go
示例15: TestApp_RunAsSubcommandParseFlags
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")
}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:25,代码来源:app_test.go
示例16: 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",
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
}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:31,代码来源:app_test.go
示例17: TestPreviewHandleSingle
func TestPreviewHandleSingle(t *testing.T) {
app := cli.NewApp()
flagset := flag.NewFlagSet("flags", 1)
flagset.String("name", "", "")
flagset.Set("name", "stack1")
c := cli.NewContext(app, flagset, nil)
cmd := &commandPreview{
Ctx: &handler.Context{
CLIContext: c,
},
}
expected := &handler.Resource{
Params: ¶msPreview{
opts: &osStacks.PreviewOpts{Name: "stack1"},
},
}
actual := &handler.Resource{
Params: ¶msPreview{
opts: &osStacks.PreviewOpts{},
},
}
err := cmd.HandleSingle(actual)
th.AssertNoErr(t, err)
th.AssertEquals(t, expected.Params.(*paramsPreview).opts.Name, actual.Params.(*paramsPreview).opts.Name)
}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:26,代码来源:preview_test.go
示例18: 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)
}
}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:57,代码来源:app_test.go
示例19: newCreateApp
func newCreateApp(flags map[string]string) *cli.Context {
app := cli.NewApp()
flagset := flag.NewFlagSet("flags", 1)
flagset.String("volume-id", "", "")
flagset.String("name", "", "")
flagset.String("description", "", "")
for k, v := range flags {
flagset.Set(k, v)
}
return cli.NewContext(app, flagset, nil)
}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:11,代码来源:create_test.go
示例20: newGetApp
func newGetApp(flags map[string]string) *cli.Context {
app := cli.NewApp()
flagset := flag.NewFlagSet("flags", 1)
flagset.String("id", "", "")
flagset.String("name", "", "")
flagset.String("stdin", "", "")
for k, v := range flags {
flagset.Set(k, v)
}
return cli.NewContext(app, flagset, nil)
}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:11,代码来源:get_test.go
注:本文中的github.com/rackspace/rack/internal/github.com/codegangsta/cli.NewApp函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论