Modifying full API example for more migrator exercise

This commit is contained in:
Dan Buch 2016-06-01 22:27:36 -04:00
parent 67c661770a
commit 288b636ba3
No known key found for this signature in database
GPG Key ID: FAEF12936DD3E3EC

View File

@ -1042,7 +1042,7 @@ func main() {
app.Version = "v19.99.0" app.Version = "v19.99.0"
app.Compiled = time.Now() app.Compiled = time.Now()
app.Authors = []cli.Author{ app.Authors = []cli.Author{
{ cli.Author{
Name: "Example Human", Name: "Example Human",
Email: "human@example.com", Email: "human@example.com",
}, },
@ -1053,7 +1053,7 @@ func main() {
app.UsageText = "contrive - demonstrating the available API" app.UsageText = "contrive - demonstrating the available API"
app.ArgsUsage = "[args and such]" app.ArgsUsage = "[args and such]"
app.Commands = []cli.Command{ app.Commands = []cli.Command{
{ cli.Command{
Name: "doo", Name: "doo",
Aliases: []string{"do"}, Aliases: []string{"do"},
Category: "motion", Category: "motion",
@ -1065,7 +1065,7 @@ func main() {
cli.BoolFlag{Name: "forever, forevvarr"}, cli.BoolFlag{Name: "forever, forevvarr"},
}, },
Subcommands: cli.Commands{ Subcommands: cli.Commands{
{ cli.Command{
Name: "wop", Name: "wop",
Action: wopAction, Action: wopAction,
}, },
@ -1147,13 +1147,13 @@ func main() {
Name: "bloop", Name: "bloop",
}) })
for _, category := range categories { for _, category := range c.App.Categories() {
fmt.Fprintf(c.App.Writer, "%s\n", category.Name) fmt.Fprintf(c.App.Writer, "%s\n", category.Name)
fmt.Fprintf(c.App.Writer, "%#v\n", category.Commands) fmt.Fprintf(c.App.Writer, "%#v\n", category.Commands)
fmt.Fprintf(c.App.Writer, "%#v\n", category.VisibleCommands()) fmt.Fprintf(c.App.Writer, "%#v\n", category.VisibleCommands())
} }
c.App.Command("doo") fmt.Printf("%#v\n", c.App.Command("doo"))
if c.Bool("infinite") { if c.Bool("infinite") {
c.App.Run([]string{"app", "doo", "wop"}) c.App.Run([]string{"app", "doo", "wop"})
} }
@ -1162,44 +1162,48 @@ func main() {
c.App.RunAsSubcommand(c) c.App.RunAsSubcommand(c)
} }
c.App.Setup() c.App.Setup()
c.App.VisibleCategories() fmt.Printf("%#v\n", c.App.VisibleCategories())
c.App.VisibleCommands() fmt.Printf("%#v\n", c.App.VisibleCommands())
c.App.VisibleFlags() fmt.Printf("%#v\n", c.App.VisibleFlags())
c.Args().First() fmt.Printf("%#v\n", c.Args().First())
c.Args().Get(1) if len(c.Args()) > 0 {
c.Args().Present() fmt.Printf("%#v\n", c.Args()[1])
c.Args().Tail() }
fmt.Printf("%#v\n", c.Args().Present())
fmt.Printf("%#v\n", c.Args().Tail())
set := flag.NewFlagSet("contrive", 0) set := flag.NewFlagSet("contrive", 0)
nc := cli.NewContext(c.App, set, c) nc := cli.NewContext(c.App, set, c)
nc.Args()
nc.Bool("nope")
nc.BoolT("nerp")
nc.Duration("howlong")
nc.Float64("hay")
nc.Generic("bloop")
nc.Int("bips")
nc.IntSlice("blups")
nc.String("snurt")
nc.StringSlice("snurkles")
nc.GlobalBool("global-nope")
nc.GlobalBoolT("global-nerp")
nc.GlobalDuration("global-howlong")
nc.GlobalFloat64("global-hay")
nc.GlobalGeneric("global-bloop")
nc.GlobalInt("global-bips")
nc.GlobalIntSlice("global-blups")
nc.GlobalString("global-snurt")
nc.GlobalStringSlice("global-snurkles")
nc.FlagNames() fmt.Printf("%#v\n", nc.Args())
nc.GlobalFlagNames() fmt.Printf("%#v\n", nc.Bool("nope"))
nc.GlobalIsSet("wat") fmt.Printf("%#v\n", nc.BoolT("nerp"))
nc.GlobalSet("wat", "nope") fmt.Printf("%#v\n", nc.Duration("howlong"))
nc.NArg() fmt.Printf("%#v\n", nc.Float64("hay"))
nc.NumFlags() fmt.Printf("%#v\n", nc.Generic("bloop"))
nc.Parent() fmt.Printf("%#v\n", nc.Int("bips"))
fmt.Printf("%#v\n", nc.IntSlice("blups"))
fmt.Printf("%#v\n", nc.String("snurt"))
fmt.Printf("%#v\n", nc.StringSlice("snurkles"))
fmt.Printf("%#v\n", nc.GlobalBool("global-nope"))
fmt.Printf("%#v\n", nc.GlobalBoolT("global-nerp"))
fmt.Printf("%#v\n", nc.GlobalDuration("global-howlong"))
fmt.Printf("%#v\n", nc.GlobalFloat64("global-hay"))
fmt.Printf("%#v\n", nc.GlobalGeneric("global-bloop"))
fmt.Printf("%#v\n", nc.GlobalInt("global-bips"))
fmt.Printf("%#v\n", nc.GlobalIntSlice("global-blups"))
fmt.Printf("%#v\n", nc.GlobalString("global-snurt"))
fmt.Printf("%#v\n", nc.GlobalStringSlice("global-snurkles"))
fmt.Printf("%#v\n", nc.FlagNames())
fmt.Printf("%#v\n", nc.GlobalFlagNames())
fmt.Printf("%#v\n", nc.GlobalIsSet("wat"))
fmt.Printf("%#v\n", nc.GlobalSet("wat", "nope"))
fmt.Printf("%#v\n", nc.NArg())
fmt.Printf("%#v\n", nc.NumFlags())
fmt.Printf("%#v\n", nc.Parent())
nc.Set("wat", "also-nope") nc.Set("wat", "also-nope")
ec := cli.NewExitError("ohwell", 86) ec := cli.NewExitError("ohwell", 86)
@ -1207,13 +1211,16 @@ func main() {
fmt.Printf("made it!\n") fmt.Printf("made it!\n")
return ec return ec
} }
app.Writer = &hexWriter{}
// just kidding there if os.Getenv("HEXY") != "" {
app.Writer = os.Stdout app.Writer = &hexWriter{}
app.ErrWriter = &hexWriter{} app.ErrWriter = &hexWriter{}
}
app.Metadata = map[string]interface{}{ app.Metadata = map[string]interface{}{
"layers": "many", "layers": "many",
"explicable": false, "explicable": false,
"whatever-values": 19.99,
} }
app.Run(os.Args) app.Run(os.Args)