diff --git a/examples/command-line-subcommands/command-line-subcommands.go b/examples/command-line-subcommands/command-line-subcommands.go index af57b21..e2d41ed 100644 --- a/examples/command-line-subcommands/command-line-subcommands.go +++ b/examples/command-line-subcommands/command-line-subcommands.go @@ -8,50 +8,50 @@ package main import ( - "flag" - "fmt" - "os" + "flag" + "fmt" + "os" ) func main() { - // We declare a subcommand using the `NewFlagSet` - // function, and proceed to define new flags specific - // for this subcommand. - fooCmd := flag.NewFlagSet("foo", flag.ExitOnError) - fooEnable := fooCmd.Bool("enable", false, "enable") - fooName := fooCmd.String("name", "", "name") + // We declare a subcommand using the `NewFlagSet` + // function, and proceed to define new flags specific + // for this subcommand. + fooCmd := flag.NewFlagSet("foo", flag.ExitOnError) + fooEnable := fooCmd.Bool("enable", false, "enable") + fooName := fooCmd.String("name", "", "name") - // For a different subcommand we can define different - // supported flags. - barCmd := flag.NewFlagSet("bar", flag.ExitOnError) - barLevel := barCmd.Int("level", 0, "level") + // For a different subcommand we can define different + // supported flags. + barCmd := flag.NewFlagSet("bar", flag.ExitOnError) + barLevel := barCmd.Int("level", 0, "level") - // The subcommand is expected as the first argument - // to the program. - if len(os.Args) < 2 { - fmt.Println("expected 'foo' or 'bar' subcommands") - os.Exit(1) - } + // The subcommand is expected as the first argument + // to the program. + if len(os.Args) < 2 { + fmt.Println("expected 'foo' or 'bar' subcommands") + os.Exit(1) + } - // Check which subcommand is invoked. - switch os.Args[1] { + // Check which subcommand is invoked. + switch os.Args[1] { - // For every subcommand, we parse its own flags and - // have access to trailing positional arguments. - case "foo": - fooCmd.Parse(os.Args[2:]) - fmt.Println("subcommand 'foo'") - fmt.Println(" enable:", *fooEnable) - fmt.Println(" name:", *fooName) - fmt.Println(" tail:", fooCmd.Args()) - case "bar": - barCmd.Parse(os.Args[2:]) - fmt.Println("subcommand 'bar'") - fmt.Println(" level:", *barLevel) - fmt.Println(" tail:", barCmd.Args()) - default: - fmt.Println("expected 'foo' or 'bar' subcommands") - os.Exit(1) - } + // For every subcommand, we parse its own flags and + // have access to trailing positional arguments. + case "foo": + fooCmd.Parse(os.Args[2:]) + fmt.Println("subcommand 'foo'") + fmt.Println(" enable:", *fooEnable) + fmt.Println(" name:", *fooName) + fmt.Println(" tail:", fooCmd.Args()) + case "bar": + barCmd.Parse(os.Args[2:]) + fmt.Println("subcommand 'bar'") + fmt.Println(" level:", *barLevel) + fmt.Println(" tail:", barCmd.Args()) + default: + fmt.Println("expected 'foo' or 'bar' subcommands") + os.Exit(1) + } } diff --git a/public/command-line-subcommands b/public/command-line-subcommands index f53c19f..4a0542d 100644 --- a/public/command-line-subcommands +++ b/public/command-line-subcommands @@ -218,7 +218,7 @@ have access to trailing positional arguments.
flag provided but not defined: -enable Usage of bar: -level int - level + level