{"action":"created","issue":{"url":"https://api.github.com/repos/alecthomas/kingpin/issues/169","repository_url":"https://api.github.com/repos/alecthomas/kingpin","labels_url":"https://api.github.com/repos/alecthomas/kingpin/issues/169/labels{/name}","comments_url":"https://api.github.com/repos/alecthomas/kingpin/issues/169/comments","events_url":"https://api.github.com/repos/alecthomas/kingpin/issues/169/events","html_url":"https://github.com/alecthomas/kingpin/issues/169","id":194444801,"number":169,"title":"Strange results with repeated parsing of help commands","user":{"login":"mkarlesky","id":1048550,"avatar_url":"https://avatars.githubusercontent.com/u/1048550?v=3","gravatar_id":"","url":"https://api.github.com/users/mkarlesky","html_url":"https://github.com/mkarlesky","followers_url":"https://api.github.com/users/mkarlesky/followers","following_url":"https://api.github.com/users/mkarlesky/following{/other_user}","gists_url":"https://api.github.com/users/mkarlesky/gists{/gist_id}","starred_url":"https://api.github.com/users/mkarlesky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mkarlesky/subscriptions","organizations_url":"https://api.github.com/users/mkarlesky/orgs","repos_url":"https://api.github.com/users/mkarlesky/repos","events_url":"https://api.github.com/users/mkarlesky/events{/privacy}","received_events_url":"https://api.github.com/users/mkarlesky/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-12-08T21:07:25Z","updated_at":"2016-12-08T23:38:42Z","closed_at":null,"body":"Thanks so much for Kingpin. It's a great package. I'm using it in two different ways in the same project. Except for this present issue, it's meeting the needs of my project handily.\r\n\r\nI'm using Kingpin both as a traditional command line processor for individual command line applications and again separately as a command string processor in a networked application. Unlike the former use case, in the latter use case, Kingpin's command line parsing is called repeatedly; command parsing errors do not cause the networked application to exit.\r\n\r\nInstantiating Kingpin and making multiple parse calls against it is working just fine in the networked application with one specific exception. Repeated calls to help commands seem to somehow corrupt tokenization and lead to incorrect help messages and the unexpected reporting of parsing errors.\r\n\r\nConsider the following call progression:\r\n\r\n1. `foo help bar`\r\n2. `foo help bar`\r\n3. `foo help baz`\r\n4. `foo help bar`\r\n5. `foo help baz`\r\n\r\nThe help returned for (1) and (2) will be spot-on correct and identical. Call (3) _might_ work as expected. Calls to (4) and (5) will certainly exhibit the reported behavior. (5) will show the help message for the `bar` command instead of the `baz` command. In addition, (4) and (5) will both report error conditions concerning an unexpected token after the EOL token (“unexpected baz”) [emitted from lines 368–370 in the latest version of parser.go].\r\n\r\nI've gone spelunking through the code and tried to trace out the processing of tokenization with `println()` calls to figure out what's going on. It's all a bit too nuanced for me to readily grasp the finer details. From what I can tell it appears that parsing context is persisting and the handling of help commands (using repeated parsing?) is not fully cleaning up that parsing context.\r\n\r\nUnlike help handling, the repeated parsing of command strings that trigger actions seems to work without any issue.\r\n\r\nAm I missing a necessary reset / cleanup step? Was Kingpin not meant to be called repeatedly in an interactive application such as I am trying to do?"},"comment":{"url":"https://api.github.com/repos/alecthomas/kingpin/issues/comments/265889143","html_url":"https://github.com/alecthomas/kingpin/issues/169#issuecomment-265889143","issue_url":"https://api.github.com/repos/alecthomas/kingpin/issues/169","id":265889143,"user":{"login":"mkarlesky","id":1048550,"avatar_url":"https://avatars.githubusercontent.com/u/1048550?v=3","gravatar_id":"","url":"https://api.github.com/users/mkarlesky","html_url":"https://github.com/mkarlesky","followers_url":"https://api.github.com/users/mkarlesky/followers","following_url":"https://api.github.com/users/mkarlesky/following{/other_user}","gists_url":"https://api.github.com/users/mkarlesky/gists{/gist_id}","starred_url":"https://api.github.com/users/mkarlesky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mkarlesky/subscriptions","organizations_url":"https://api.github.com/users/mkarlesky/orgs","repos_url":"https://api.github.com/users/mkarlesky/repos","events_url":"https://api.github.com/users/mkarlesky/events{/privacy}","received_events_url":"https://api.github.com/users/mkarlesky/received_events","type":"User","site_admin":false},"created_at":"2016-12-08T23:38:42Z","updated_at":"2016-12-08T23:38:42Z","body":"Attached is a small example that exercises Kingpin “interactively” using stripped down code from my project. The test app first prints top-level usage. Then the app makes multiple calls to `help` for two commands. Finally, for good measure, the app executes the two actions attached to the commands. The output I see when running this little app is at bottom.\r\n\r\n[kingpin-test.zip](https://github.com/alecthomas/kingpin/files/640824/kingpin-test.zip)\r\n\r\nThe meat of the test case is found in calling `help` 3 times for 2 commands ‘foo’ and ‘bar’:\r\n\r\n1. `help foo`\r\n2. `help foo`\r\n3. `help bar`\r\n\r\nThe result of the first call is as expected. The result of the second call produces the correct help message but reports an unexpected token beyond the end of the command. The result of the third call produces a help message for foo instead of bar and reports a token beyond the end of the command string as well.\r\n\r\nThanks so much for any help in figuring this out.\r\n\r\n```=== Usage() ===\r\n\r\nusage: kingpin-test [<flags>] <command> [<args> ...]\r\n\r\nTesting a help parsing bug\r\n\r\nFlags:\r\n\r\nCommands:\r\n  help [<command>...]\r\n    Show help.\r\n\r\n  foo\r\n    Foo does some serious fu\r\n\r\n  bar\r\n    Bar does it up\r\n\r\n\r\n\r\n-----------\r\n\r\n=== \"help foo\" ===\r\n\r\nusage: kingpin-test foo\r\n\r\nFoo does some serious fu\r\n\r\nFlags:\r\n\r\n\r\n-----------\r\n\r\n=== \"help foo\" ===\r\n\r\nkingpin-test: error: unexpected foo\r\nusage: kingpin-test foo\r\n\r\nFoo does some serious fu\r\n\r\nFlags:\r\n\r\n\r\n-----------\r\n\r\n=== \"help bar\" ===\r\n\r\nkingpin-test: error: unexpected foo\r\nusage: kingpin-test foo\r\n\r\nFoo does some serious fu\r\n\r\nFlags:\r\n\r\n\r\n-----------\r\n\r\n=== fooDoer() ===\r\n\r\n=== barDoer() ===\r\n```\r\n"}}
{"actor":{"display_login":"mkarlesky"}}