Created
September 23, 2014 03:55
-
-
Save technosophos/32b1815a4ff26cf5bf48 to your computer and use it in GitHub Desktop.
Example of Cookoo subcommand.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "github.com/Masterminds/cookoo" | |
| "github.com/Masterminds/cookoo/cli" | |
| "github.com/Masterminds/cookoo/fmt" | |
| "flag" | |
| ) | |
| func main() { | |
| reg, router, cxt := cookoo.Cookoo() | |
| // global flags | |
| flags := flag.NewFlagSet("global", flag.PanicOnError) | |
| flags.Bool("h", false, "Print help") | |
| // Create a new app | |
| app := cli.New(reg, router, cxt).Help("Test", "test -h", flags) | |
| // Create a new subcommand on that app | |
| app.Subcommand("test", "A test route.", "example test", nil). | |
| Does(fmt.Println, "out").Using("content").WithDefault("Hello World") | |
| // Subcommand with flags. | |
| helloFlags := flag.NewFlagSet("test", flag.ContinueOnError) | |
| helloFlags.Bool("h", false, "Print help") | |
| helloFlags.String("n", "World!", "A name to greet.") | |
| app.Subcommand("hello", "Print hello.", "example hello -n Matt", helloFlags). | |
| Does(fmt.Printf, "out"). | |
| Using("format").WithDefault("Hello %s\n"). | |
| Using("0").WithDefault("World").From("cxt:n") | |
| // Run the app, and let it figure out which subcommand to run. | |
| app.RunSubcommand() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment