{"action":"created","issue":{"url":"https://api.github.com/repos/spf13/pflag/issues/195","repository_url":"https://api.github.com/repos/spf13/pflag","labels_url":"https://api.github.com/repos/spf13/pflag/issues/195/labels{/name}","comments_url":"https://api.github.com/repos/spf13/pflag/issues/195/comments","events_url":"https://api.github.com/repos/spf13/pflag/issues/195/events","html_url":"https://github.com/spf13/pflag/issues/195","id":389018223,"node_id":"MDU6SXNzdWUzODkwMTgyMjM=","number":195,"title":"How to set subcommand specific flags","user":{"login":"sj14","id":6493966,"node_id":"MDQ6VXNlcjY0OTM5NjY=","avatar_url":"https://avatars0.githubusercontent.com/u/6493966?v=4","gravatar_id":"","url":"https://api.github.com/users/sj14","html_url":"https://github.com/sj14","followers_url":"https://api.github.com/users/sj14/followers","following_url":"https://api.github.com/users/sj14/following{/other_user}","gists_url":"https://api.github.com/users/sj14/gists{/gist_id}","starred_url":"https://api.github.com/users/sj14/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sj14/subscriptions","organizations_url":"https://api.github.com/users/sj14/orgs","repos_url":"https://api.github.com/users/sj14/repos","events_url":"https://api.github.com/users/sj14/events{/privacy}","received_events_url":"https://api.github.com/users/sj14/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-12-09T12:34:48Z","updated_at":"2018-12-09T14:54:08Z","closed_at":null,"author_association":"NONE","body":"Hi, I try to use `pflag` for sub commands with multiple flag sets. Please see the example below.\r\n\r\n``` go\r\npackage main\r\n\r\nimport (\r\n\t\"fmt\"\r\n\t\"log\"\r\n\t\"os\"\r\n\r\n\t\"github.com/spf13/pflag\"\r\n)\r\n\r\nfunc main() {\r\n\tdefaults := pflag.NewFlagSet(\"defaults for all commands\", pflag.ExitOnError)\r\n\tforAll := defaults.String(\"all\", \"visible for all commands\", \"visible for all commands\")\r\n\r\n\tcmdA := pflag.NewFlagSet(\"cmda\", pflag.ExitOnError)\r\n\tcmdAspecific := cmdA.String(\"aspec\", \"only visible for cmd A\", \"only visible for cmd A\")\r\n\tcmdA.AddFlagSet(defaults)\r\n\r\n\tcmdB := pflag.NewFlagSet(\"cmdb\", pflag.ExitOnError)\r\n\tcmdBspecific := cmdA.String(\"bspec\", \"only visible for cmd B\", \"only visible for cmd B\")\r\n\tcmdB.AddFlagSet(defaults)\r\n\r\n\tdefaults.Parse(os.Args)\r\n\r\n\tif len(os.Args) == 1 {\r\n\t\tlog.Fatal(\"no subcommand given\")\r\n\t}\r\n\r\n\tswitch os.Args[1] {\r\n\tcase \"cmda\":\r\n\t\tcmdA.Parse(os.Args[2:])\r\n\t\tfmt.Println(*cmdAspecific)\r\n\t\tfmt.Println(*forAll)\r\n\tcase \"cmdb\":\r\n\t\tcmdB.Parse(os.Args[2:])\r\n\t\tfmt.Println(*cmdBspecific)\r\n\t\tfmt.Println(*forAll)\r\n\tdefault:\r\n\t\tfmt.Printf(\"%q is no valid subcommand.\\n\", os.Args[1])\r\n\t\tos.Exit(2)\r\n\t}\r\n}\r\n```\r\n\r\n`cmda` / `cmdb` without flags works as expected.\r\n``` \r\ngo run main.go cmdb\r\nonly visible for cmd B\r\nvisible for all commands\r\n```\r\n\r\nBut not with flags. I thought this should be possbile, where is my mistake?\r\n\r\n```\r\ngo run main.go cmdb --bspec asd\r\nunknown flag: --bspec\r\nUsage of defaults for all commands:\r\n      --all string   visible for all commands (default \"visible for all commands\")\r\nunknown flag: --bspec\r\nexit status 2\r\n```"},"comment":{"url":"https://api.github.com/repos/spf13/pflag/issues/comments/445544288","html_url":"https://github.com/spf13/pflag/issues/195#issuecomment-445544288","issue_url":"https://api.github.com/repos/spf13/pflag/issues/195","id":445544288,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0NTU0NDI4OA==","user":{"login":"sj14","id":6493966,"node_id":"MDQ6VXNlcjY0OTM5NjY=","avatar_url":"https://avatars0.githubusercontent.com/u/6493966?v=4","gravatar_id":"","url":"https://api.github.com/users/sj14","html_url":"https://github.com/sj14","followers_url":"https://api.github.com/users/sj14/followers","following_url":"https://api.github.com/users/sj14/following{/other_user}","gists_url":"https://api.github.com/users/sj14/gists{/gist_id}","starred_url":"https://api.github.com/users/sj14/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sj14/subscriptions","organizations_url":"https://api.github.com/users/sj14/orgs","repos_url":"https://api.github.com/users/sj14/repos","events_url":"https://api.github.com/users/sj14/events{/privacy}","received_events_url":"https://api.github.com/users/sj14/received_events","type":"User","site_admin":false},"created_at":"2018-12-09T14:54:08Z","updated_at":"2018-12-09T14:54:08Z","author_association":"NONE","body":"@eparis oh, you are right. But after changing it, it's still the same issue."}}
{"actor":{"display_login":"sj14"}}