本文整理汇总了Golang中github.com/jrperritt/rack/internal/github.com/codegangsta/cli.NewContext函数的典型用法代码示例。如果您正苦于以下问题:Golang NewContext函数的具体用法?Golang NewContext怎么用?Golang NewContext使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewContext函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestContext_NumFlags
func TestContext_NumFlags(t *testing.T) {
set := flag.NewFlagSet("test", 0)
set.Bool("myflag", false, "doc")
set.String("otherflag", "hello world", "doc")
globalSet := flag.NewFlagSet("test", 0)
globalSet.Bool("myflagGlobal", true, "doc")
globalCtx := cli.NewContext(nil, globalSet, nil)
c := cli.NewContext(nil, set, globalCtx)
set.Parse([]string{"--myflag", "--otherflag=foo"})
globalSet.Parse([]string{"--myflagGlobal"})
expect(t, c.NumFlags(), 2)
}
开发者ID:hdansou,项目名称:rack,代码行数:12,代码来源:context_test.go
示例2: TestNewContext
func TestNewContext(t *testing.T) {
set := flag.NewFlagSet("test", 0)
set.Int("myflag", 12, "doc")
globalSet := flag.NewFlagSet("test", 0)
globalSet.Int("myflag", 42, "doc")
globalCtx := cli.NewContext(nil, globalSet, nil)
command := cli.Command{Name: "mycommand"}
c := cli.NewContext(nil, set, globalCtx)
c.Command = command
expect(t, c.Int("myflag"), 12)
expect(t, c.GlobalInt("myflag"), 42)
expect(t, c.Command.Name, "mycommand")
}
开发者ID:hdansou,项目名称:rack,代码行数:13,代码来源:context_test.go
示例3: TestContext_IsSet
func TestContext_IsSet(t *testing.T) {
set := flag.NewFlagSet("test", 0)
set.Bool("myflag", false, "doc")
set.String("otherflag", "hello world", "doc")
globalSet := flag.NewFlagSet("test", 0)
globalSet.Bool("myflagGlobal", true, "doc")
globalCtx := cli.NewContext(nil, globalSet, nil)
c := cli.NewContext(nil, set, globalCtx)
set.Parse([]string{"--myflag", "bat", "baz"})
globalSet.Parse([]string{"--myflagGlobal", "bat", "baz"})
expect(t, c.IsSet("myflag"), true)
expect(t, c.IsSet("otherflag"), false)
expect(t, c.IsSet("bogusflag"), false)
expect(t, c.IsSet("myflagGlobal"), false)
}
开发者ID:hdansou,项目名称:rack,代码行数:15,代码来源:context_test.go
示例4: 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:hdansou,项目名称:rack,代码行数:27,代码来源:upload_test.go
示例5: 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:hdansou,项目名称:rack,代码行数:28,代码来源:create_test.go
示例6: 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:harshalhshah,项目名称:rack,代码行数:25,代码来源:delete_test.go
示例7: 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:hdansou,项目名称:rack,代码行数:35,代码来源:list_test.go
示例8: 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.Bool("json", false, "")
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:mrhillsman,项目名称:rack,代码行数:27,代码来源:generate_test.go
示例9: TestGetHandleSingle
func TestGetHandleSingle(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 := &commandGet{
Ctx: &handler.Context{
CLIContext: c,
ServiceClient: client.ServiceClient(),
},
}
expected := &handler.Resource{
Params: ¶msGet{
server: "server1",
},
}
actual := &handler.Resource{
Params: ¶msGet{},
}
err := cmd.HandleSingle(actual)
th.AssertNoErr(t, err)
th.AssertEquals(t, expected.Params.(*paramsGet).server, actual.Params.(*paramsGet).server)
}
开发者ID:hdansou,项目名称:rack,代码行数:30,代码来源:get_test.go
示例10: TestGenerateHandleSingle
func TestGenerateHandleSingle(t *testing.T) {
app := cli.NewApp()
flagset := flag.NewFlagSet("flags", 1)
flagset.String("name", "", "")
flagset.Set("name", "keypair1Name")
c := cli.NewContext(app, flagset, nil)
cmd := &commandGenerate{
Ctx: &handler.Context{
CLIContext: c,
},
}
expected := &handler.Resource{
Params: ¶msGenerate{
opts: &osKeypairs.CreateOpts{
Name: "keypair1Name",
},
},
}
actual := &handler.Resource{
Params: ¶msGenerate{
opts: &osKeypairs.CreateOpts{},
},
}
err := cmd.HandleSingle(actual)
th.AssertNoErr(t, err)
th.AssertEquals(t, *expected.Params.(*paramsGenerate).opts, *actual.Params.(*paramsGenerate).opts)
}
开发者ID:mrhillsman,项目名称:rack,代码行数:27,代码来源:generate_test.go
示例11: TestContext_Args
func TestContext_Args(t *testing.T) {
set := flag.NewFlagSet("test", 0)
set.Bool("myflag", false, "doc")
c := cli.NewContext(nil, set, nil)
set.Parse([]string{"--myflag", "bat", "baz"})
expect(t, len(c.Args()), 2)
expect(t, c.Bool("myflag"), true)
}
开发者ID:hdansou,项目名称:rack,代码行数:8,代码来源:context_test.go
示例12: TestDeleteContext
func TestDeleteContext(t *testing.T) {
app := cli.NewApp()
flagset := flag.NewFlagSet("flags", 1)
c := cli.NewContext(app, flagset, nil)
cmd := &commandDelete{
Ctx: &handler.Context{
CLIContext: c,
},
}
expected := cmd.Ctx
actual := cmd.Context()
th.AssertDeepEquals(t, expected, actual)
}
开发者ID:hdansou,项目名称:rack,代码行数:13,代码来源:delete_test.go
示例13: Test_ShowAppHelp_NoAuthor
func Test_ShowAppHelp_NoAuthor(t *testing.T) {
output := new(bytes.Buffer)
app := cli.NewApp()
app.Writer = output
c := cli.NewContext(app, nil, nil)
cli.ShowAppHelp(c)
if bytes.Index(output.Bytes(), []byte("AUTHOR(S):")) != -1 {
t.Errorf("expected\n%snot to include %s", output.String(), "AUTHOR(S):")
}
}
开发者ID:hdansou,项目名称:rack,代码行数:13,代码来源:help_test.go
示例14: TestCreateHandleFlags
func TestCreateHandleFlags(t *testing.T) {
app := cli.NewApp()
flagset := flag.NewFlagSet("flags", 1)
flagset.String("image-id", "", "")
flagset.String("flavor-id", "", "")
flagset.String("security-groups", "", "")
flagset.String("networks", "", "")
flagset.String("metadata", "", "")
flagset.String("admin-pass", "", "")
flagset.String("keypair", "", "")
flagset.Set("image-id", "13ba-75c0-4483-acf9")
flagset.Set("flavor-id", "1234-b95f-ac5b-cd23")
flagset.Set("security-groups", "sg1,sg2,sg3")
flagset.Set("networks", "1111-2222-3333-4444,5555-7777-8888-9999")
flagset.Set("metadata", "img=foo,flavor=bar")
flagset.Set("admin-pass", "secret")
flagset.Set("keypair", "kp1")
c := cli.NewContext(app, flagset, nil)
cmd := &commandCreate{
Ctx: &handler.Context{
CLIContext: c,
},
}
expected := &handler.Resource{
Params: ¶msCreate{
opts: &servers.CreateOpts{
ImageRef: "13ba-75c0-4483-acf9",
FlavorRef: "1234-b95f-ac5b-cd23",
SecurityGroups: []string{"sg1", "sg2", "sg3"},
Networks: []osServers.Network{
{
UUID: "1111-2222-3333-4444",
},
{
UUID: "5555-7777-8888-9999",
},
},
Metadata: map[string]string{
"img": "foo",
"flavor": "bar",
},
AdminPass: "secret",
KeyPair: "kp1",
},
},
}
actual := &handler.Resource{}
err := cmd.HandleFlags(actual)
th.AssertNoErr(t, err)
th.AssertDeepEquals(t, *expected.Params.(*paramsCreate).opts, *actual.Params.(*paramsCreate).opts)
}
开发者ID:mrhillsman,项目名称:rack,代码行数:51,代码来源:create_test.go
示例15: TestRebuildHandleFlags
func TestRebuildHandleFlags(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.String("image-id", "", "")
flagset.String("admin-pass", "", "")
flagset.String("ipv4", "", "")
flagset.String("ipv6", "", "")
flagset.String("metadata", "", "")
flagset.String("rename", "", "")
flagset.Set("id", "server1")
flagset.Set("image-id", "123456789")
flagset.Set("admin-pass", "secret")
flagset.Set("ipv4", "123.45.67.89")
flagset.Set("metadata", "img=bar,flavor=foo")
flagset.Set("rename", "server1Rename")
c := cli.NewContext(app, flagset, nil)
cmd := &commandRebuild{
Ctx: &handler.Context{
CLIContext: c,
},
}
expected := &handler.Resource{
Params: ¶msRebuild{
opts: &servers.RebuildOpts{
ImageID: "123456789",
AdminPass: "secret",
AccessIPv4: "123.45.67.89",
Metadata: map[string]string{
"img": "bar",
"flavor": "foo",
},
Name: "server1Rename",
},
serverID: "server1",
},
}
actual := &handler.Resource{}
err := cmd.HandleFlags(actual)
th.AssertNoErr(t, err)
th.AssertDeepEquals(t, *expected.Params.(*paramsRebuild).opts, *actual.Params.(*paramsRebuild).opts)
}
开发者ID:hdansou,项目名称:rack,代码行数:49,代码来源:rebuild_test.go
示例16: TestDeleteHandleFlags
func TestDeleteHandleFlags(t *testing.T) {
app := cli.NewApp()
flagset := flag.NewFlagSet("flags", 1)
c := cli.NewContext(app, flagset, nil)
cmd := &commandDelete{
Ctx: &handler.Context{
CLIContext: c,
},
}
expected := &handler.Resource{
Params: ¶msDelete{},
}
actual := &handler.Resource{}
err := cmd.HandleFlags(actual)
th.AssertNoErr(t, err)
th.AssertDeepEquals(t, expected.Params.(*paramsDelete), actual.Params.(*paramsDelete))
}
开发者ID:harshalhshah,项目名称:rack,代码行数:17,代码来源:delete_test.go
示例17: TestCommandDoNotIgnoreFlags
func TestCommandDoNotIgnoreFlags(t *testing.T) {
app := cli.NewApp()
set := flag.NewFlagSet("test", 0)
test := []string{"blah", "blah", "-break"}
set.Parse(test)
c := cli.NewContext(app, set, nil)
command := cli.Command{
Name: "test-cmd",
Aliases: []string{"tc"},
Usage: "this is for testing",
Description: "testing",
Action: func(_ *cli.Context) {},
}
err := command.Run(c)
expect(t, err.Error(), "flag provided but not defined: -break")
}
开发者ID:hdansou,项目名称:rack,代码行数:19,代码来源:command_test.go
示例18: TestAppVersionPrinter
func TestAppVersionPrinter(t *testing.T) {
oldPrinter := cli.VersionPrinter
defer func() {
cli.VersionPrinter = oldPrinter
}()
var wasCalled = false
cli.VersionPrinter = func(c *cli.Context) {
wasCalled = true
}
app := cli.NewApp()
ctx := cli.NewContext(app, nil, nil)
cli.ShowVersion(ctx)
if wasCalled == false {
t.Errorf("Version printer expected to be called, but was not")
}
}
开发者ID:hdansou,项目名称:rack,代码行数:19,代码来源:app_test.go
示例19: TestCommandIgnoreFlags
func TestCommandIgnoreFlags(t *testing.T) {
app := cli.NewApp()
set := flag.NewFlagSet("test", 0)
test := []string{"blah", "blah"}
set.Parse(test)
c := cli.NewContext(app, set, nil)
command := cli.Command{
Name: "test-cmd",
Aliases: []string{"tc"},
Usage: "this is for testing",
Description: "testing",
Action: func(_ *cli.Context) {},
SkipFlagParsing: true,
}
err := command.Run(c)
expect(t, err, nil)
}
开发者ID:hdansou,项目名称:rack,代码行数:20,代码来源:command_test.go
示例20: TestRebootHandleFlags
func TestRebootHandleFlags(t *testing.T) {
app := cli.NewApp()
flagset := flag.NewFlagSet("flags", 1)
flagset.Bool("soft", false, "")
flagset.Bool("hard", false, "")
flagset.Set("soft", "true")
c := cli.NewContext(app, flagset, nil)
cmd := &commandReboot{
Ctx: &handler.Context{
CLIContext: c,
},
}
expected := &handler.Resource{
Params: ¶msReboot{
how: osServers.OSReboot,
},
}
actual := &handler.Resource{}
err := cmd.HandleFlags(actual)
th.AssertNoErr(t, err)
th.AssertDeepEquals(t, *expected.Params.(*paramsReboot), *actual.Params.(*paramsReboot))
}
开发者ID:hdansou,项目名称:rack,代码行数:22,代码来源:reboot_test.go
注:本文中的github.com/jrperritt/rack/internal/github.com/codegangsta/cli.NewContext函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论