本文整理汇总了Golang中github.com/convox/cli/Godeps/_workspace/src/github.com/codegangsta/cli.NewContext函数的典型用法代码示例。如果您正苦于以下问题:Golang NewContext函数的具体用法?Golang NewContext怎么用?Golang NewContext使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewContext函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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:nguyendangminh,项目名称:cli,代码行数: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:nguyendangminh,项目名称:cli,代码行数: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:nguyendangminh,项目名称:cli,代码行数:15,代码来源:context_test.go
示例4: 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:nguyendangminh,项目名称:cli,代码行数:8,代码来源:context_test.go
示例5: 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:nguyendangminh,项目名称:cli,代码行数:13,代码来源:help_test.go
示例6: Test_ShowAppHelp_NoVersion
func Test_ShowAppHelp_NoVersion(t *testing.T) {
output := new(bytes.Buffer)
app := cli.NewApp()
app.Writer = output
app.Version = ""
c := cli.NewContext(app, nil, nil)
cli.ShowAppHelp(c)
if bytes.Index(output.Bytes(), []byte("VERSION:")) != -1 {
t.Errorf("expected\n%snot to include %s", output.String(), "VERSION:")
}
}
开发者ID:nguyendangminh,项目名称:cli,代码行数:15,代码来源:help_test.go
示例7: 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, set)
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:rjocoleman,项目名称:cli,代码行数:19,代码来源:command_test.go
示例8: 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:nguyendangminh,项目名称:cli,代码行数:19,代码来源:app_test.go
示例9: 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, set)
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:rjocoleman,项目名称:cli,代码行数:20,代码来源:command_test.go
示例10: TestContext_BoolT
func TestContext_BoolT(t *testing.T) {
set := flag.NewFlagSet("test", 0)
set.Bool("myflag", true, "doc")
c := cli.NewContext(nil, set, nil)
expect(t, c.BoolT("myflag"), true)
}
开发者ID:nguyendangminh,项目名称:cli,代码行数:6,代码来源:context_test.go
示例11: TestContext_String
func TestContext_String(t *testing.T) {
set := flag.NewFlagSet("test", 0)
set.String("myflag", "hello world", "doc")
c := cli.NewContext(nil, set, nil)
expect(t, c.String("myflag"), "hello world")
}
开发者ID:nguyendangminh,项目名称:cli,代码行数:6,代码来源:context_test.go
示例12: TestContext_Duration
func TestContext_Duration(t *testing.T) {
set := flag.NewFlagSet("test", 0)
set.Duration("myflag", time.Duration(12*time.Second), "doc")
c := cli.NewContext(nil, set, nil)
expect(t, c.Duration("myflag"), time.Duration(12*time.Second))
}
开发者ID:nguyendangminh,项目名称:cli,代码行数:6,代码来源:context_test.go
示例13: TestContext_Int
func TestContext_Int(t *testing.T) {
set := flag.NewFlagSet("test", 0)
set.Int("myflag", 12, "doc")
c := cli.NewContext(nil, set, nil)
expect(t, c.Int("myflag"), 12)
}
开发者ID:nguyendangminh,项目名称:cli,代码行数:6,代码来源:context_test.go
示例14: TestContext_Bool
func TestContext_Bool(t *testing.T) {
set := flag.NewFlagSet("test", 0)
set.Bool("myflag", false, "doc")
c := cli.NewContext(nil, set, set)
expect(t, c.Bool("myflag"), false)
}
开发者ID:rjocoleman,项目名称:cli,代码行数:6,代码来源:context_test.go
注:本文中的github.com/convox/cli/Godeps/_workspace/src/github.com/codegangsta/cli.NewContext函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论