Fix global flags in Subcommands

closes #69
This commit is contained in:
Philippe Lafoucrière
2014-07-06 11:04:48 +02:00
parent bb9189510a
commit df5fb46048
2 changed files with 32 additions and 2 deletions

View File

@@ -2,9 +2,10 @@ package cli_test
import (
"fmt"
"github.com/codegangsta/cli"
"os"
"testing"
"github.com/codegangsta/cli"
)
func ExampleApp() {
@@ -369,3 +370,32 @@ func TestAppCommandNotFound(t *testing.T) {
expect(t, beforeRun, true)
expect(t, subcommandRun, false)
}
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)
}