{"action":"created","issue":{"url":"https://api.github.com/repos/codegangsta/cli/issues/191","labels_url":"https://api.github.com/repos/codegangsta/cli/issues/191/labels{/name}","comments_url":"https://api.github.com/repos/codegangsta/cli/issues/191/comments","events_url":"https://api.github.com/repos/codegangsta/cli/issues/191/events","html_url":"https://github.com/codegangsta/cli/issues/191","id":60437228,"number":191,"title":"subcommands silently ignore app level flags","user":{"login":"lcowell","id":79169,"avatar_url":"https://avatars.githubusercontent.com/u/79169?v=3","gravatar_id":"","url":"https://api.github.com/users/lcowell","html_url":"https://github.com/lcowell","followers_url":"https://api.github.com/users/lcowell/followers","following_url":"https://api.github.com/users/lcowell/following{/other_user}","gists_url":"https://api.github.com/users/lcowell/gists{/gist_id}","starred_url":"https://api.github.com/users/lcowell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lcowell/subscriptions","organizations_url":"https://api.github.com/users/lcowell/orgs","repos_url":"https://api.github.com/users/lcowell/repos","events_url":"https://api.github.com/users/lcowell/events{/privacy}","received_events_url":"https://api.github.com/users/lcowell/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-03-10T01:26:02Z","updated_at":"2015-10-13T23:02:11Z","closed_at":null,"body":"This app (see below) has a `limit` flag and an `info` command. If I call the app like this:\r\n\r\n    ./boom --limit 100 info\r\n\r\nThe `limit` flag is not set when I call the `info` action. If I move those flags to the command's definition, then I can call the app like this:\r\n\r\n    ./boom info --limit 100\r\n\r\nHowever, in my real world use case,  flags like limit apply to most, if not all the commands.\r\n\r\nI think flags declared at the app level, should be available to any command and flags declared at the command level, should only be available to that particular command. I think that if a flag is not accepted, the user should be informed of this.\r\n\r\nThanks for building this awesome tool! Please let me know if there's anything else I can do to help.\r\n\r\nHere's the code I'm referring to:\r\n```go\r\npackage main\r\n\r\nimport (\r\n\t\"fmt\"\r\n\t\"os\"\r\n\r\n\t\"github.com/codegangsta/cli\"\r\n)\r\n\r\nfunc main() {\r\n\tapp := cli.NewApp()\r\n\tapp.Name = \"boom\"\r\n\tapp.Usage = \"make an explosive entrance\"\r\n\tapp.Flags = []cli.Flag{\r\n\t\tcli.IntFlag{\r\n\t\t\tName: \"limit, l\",\r\n\t\t},\r\n\t}\r\n\tapp.Commands = []cli.Command{\r\n\t\t{\r\n\t\t\tName:      \"info\",\r\n\t\t\tShortName: \"i\",\r\n\t\t\tAction: func(c *cli.Context) {\r\n\t\t\t\tlimit := c.Int(\"limit\")\r\n\t\t\t\tfmt.Println(limit)\r\n\t\t\t},\r\n\t\t},\r\n\t}\r\n\r\n\tapp.Run(os.Args)\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/codegangsta/cli/issues/comments/147878119","html_url":"https://github.com/codegangsta/cli/issues/191#issuecomment-147878119","issue_url":"https://api.github.com/repos/codegangsta/cli/issues/191","id":147878119,"user":{"login":"cactus","id":59039,"avatar_url":"https://avatars.githubusercontent.com/u/59039?v=3","gravatar_id":"","url":"https://api.github.com/users/cactus","html_url":"https://github.com/cactus","followers_url":"https://api.github.com/users/cactus/followers","following_url":"https://api.github.com/users/cactus/following{/other_user}","gists_url":"https://api.github.com/users/cactus/gists{/gist_id}","starred_url":"https://api.github.com/users/cactus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cactus/subscriptions","organizations_url":"https://api.github.com/users/cactus/orgs","repos_url":"https://api.github.com/users/cactus/repos","events_url":"https://api.github.com/users/cactus/events{/privacy}","received_events_url":"https://api.github.com/users/cactus/received_events","type":"User","site_admin":false},"created_at":"2015-10-13T23:02:11Z","updated_at":"2015-10-13T23:02:11Z","body":"If maintainers wish to support this (parent flags always available to child contexts), then I think this could be pretty easily accomplished by adding a method similar to this...\r\n\r\n```\r\n// lookup flags via post-order walking (child first, then parent)\r\n// returning the first match, or nil if no match\r\nfunc lookupPostOrderFlagSet(name string, ctx *Context) *flag.FlagSet {\r\n\tif f := ctx.flagSet.Lookup(name); f != nil {\r\n\t\treturn ctx.flagSet\r\n\t}\r\n\treturn lookupGlobalFlagSet(name, ctx)\r\n}\r\n```\r\n\r\nand then changing the non-global lookups to use the above function in a similar fashion to how the global* lookups current work. Ex:\r\n\r\n```\r\nfunc (c *Context) IntSlice(name string) []int {\r\n\tif fs := lookupPostOrderFlagSet(name, c); fs != nil {\r\n\t\treturn lookupIntSlice(name, fs)\r\n\t}\r\n\treturn nil\r\n}\r\n```\r\n\r\nAnother option would be to just add an additional set of lookup methods that behave this way:\r\n\r\n```\r\n// Looks up the value of a local int slice flag, if no int slice flag exists\r\n// then parent contexts are checked recursively for the int slice flag.\r\n// returns nil if no flag exists locally or in parent contexts\r\nfunc (c *Context) AnyIntSlice(name string) []int {\r\n\tif fs := lookupPostOrderFlagSet(name, c); fs != nil {\r\n\t\treturn lookupIntSlice(name, fs)\r\n\t}\r\n\treturn nil\r\n}\r\n```"}}