示例#1
0
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")
}
示例#2
0
文件: new.go 项目: ricardo-rossi/nut
func runNew(c *cli.Context) {
	if len(c.Args()) == 0 {
		check(fmt.Errorf("Usage: \n    nut new <path>"))
	}

	name := c.Args()[0]

	err := os.Mkdir(name, os.ModePerm)
	check(err)

	err = createNutToml(name)
	check(err)

	err = createReadmeMd(name)
	check(err)

	err = createGitIgnore(name)
	check(err)

	err = createMainGo(name)
	check(err)
}