{"action":"created","issue":{"url":"https://api.github.com/repos/deis/workflow-cli/issues/255","repository_url":"https://api.github.com/repos/deis/workflow-cli","labels_url":"https://api.github.com/repos/deis/workflow-cli/issues/255/labels{/name}","comments_url":"https://api.github.com/repos/deis/workflow-cli/issues/255/comments","events_url":"https://api.github.com/repos/deis/workflow-cli/issues/255/events","html_url":"https://github.com/deis/workflow-cli/pull/255","id":180129098,"number":255,"title":"fix(deis.go): do not add top level command to cmdArgs","user":{"login":"smt116","id":619324,"avatar_url":"https://avatars.githubusercontent.com/u/619324?v=3","gravatar_id":"","url":"https://api.github.com/users/smt116","html_url":"https://github.com/smt116","followers_url":"https://api.github.com/users/smt116/followers","following_url":"https://api.github.com/users/smt116/following{/other_user}","gists_url":"https://api.github.com/users/smt116/gists{/gist_id}","starred_url":"https://api.github.com/users/smt116/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smt116/subscriptions","organizations_url":"https://api.github.com/users/smt116/orgs","repos_url":"https://api.github.com/users/smt116/repos","events_url":"https://api.github.com/users/smt116/events{/privacy}","received_events_url":"https://api.github.com/users/smt116/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-09-29T18:40:30Z","updated_at":"2016-09-29T18:40:32Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/deis/workflow-cli/pulls/255","html_url":"https://github.com/deis/workflow-cli/pull/255","diff_url":"https://github.com/deis/workflow-cli/pull/255.diff","patch_url":"https://github.com/deis/workflow-cli/pull/255.patch"},"body":"**Ported from V1: https://github.com/deis/deis/pull/5099.**\r\n\r\n---\r\n\r\n## Background\r\n\r\nWe have a private PaaS with multiple Deis clusters (staging + two productions at the moment). We have also a tool that allows us to manage all clusters from a single web panel. It also connects other APIs such as servers provider and DNS provider. As the result we can perform actions that touches many parts of the system (for example create DNS records for all Deis workers and make CNAME to use with `DEISCTL_TUNNEL` or create a database and assign `DATABASE_URL` for a given application). We have also created plugins to extend Deis CLI. For example there is a support for database (+backups) management and easy SSH access for our developers.\r\n\r\n## Problem\r\n\r\nWe have `deis backups:[create|show|restore|list]` commands and we want to show usage help if user tries `deis backups`. There is a problem in such case because Deis CLI invokes `deis-backups backups`. Without additional support on the plugin side, it will throw an invalid command error.\r\n\r\n## Solution\r\n\r\nWe can solve it on the plugin side to handle unexpected arguments, but it feels not okay. Instead, Deis CLI should skip top level command (`backups` in this case) in `cmdArgv`. It already does that when used as `deis backups:list` or even `deis backups:`.\r\n\r\n## Code snippets\r\n\r\nThe output contains output using the following patch:\r\n\r\n```diff\r\ndiff --git a/deis.go b/deis.go\r\nindex 6096618..85e574e 100644\r\n--- a/deis.go\r\n+++ b/deis.go\r\n@@ -165,6 +165,12 @@ Use 'git push deis master' to deploy to an application.\r\n\r\n                cmdArgv := prepareCmdArgs(command, argv)\r\n\r\n+               fmt.Fprintf(wErr, \"command: %s\\n\", command)\r\n+               fmt.Fprintf(wErr, \"argv: %s\\n\", argv)\r\n+               fmt.Fprintf(wErr, \"binary: %v\\n\", binary)\r\n+               fmt.Fprintf(wErr, \"cmdArgv: %v\\n\", cmdArgv)\r\n+               return 1\r\n+\r\n                err = syscall.Exec(binary, cmdArgv, env)\r\n                if err != nil {\r\n                        parser.PrintUsage(&cmdr)\r\n```\r\n\r\n### After\r\n\r\n```bash\r\nworkflow-cli λ ./_dist/deis backups\r\ncommand: backups\r\nargv: [backups]\r\nbinary: /Users/smefju/.rbenv/shims/deis-backups\r\ncmdArgv: [deis-backups]\r\n\r\nworkflow-cli λ ./_dist/deis backups:list\r\ncommand: backups\r\nargv: [backups:list]\r\nbinary: /Users/smefju/.rbenv/shims/deis-backups\r\ncmdArgv: [deis-backups list]\r\n\r\nworkflow-cli λ ./_dist/deis backups --info\r\ncommand: backups\r\nargv: [backups --info]\r\nbinary: /Users/smefju/.rbenv/shims/deis-backups\r\ncmdArgv: [deis-backups --info]\r\n\r\nworkflow-cli λ ./_dist/deis backups:create --info\r\ncommand: backups\r\nargv: [backups:create --info]\r\nbinary: /Users/smefju/.rbenv/shims/deis-backups\r\ncmdArgv: [deis-backups create --info]\r\n```\r\n\r\n---\r\n\r\n@bacongobbler I have extracted code to the `prepareCmdArgs` function to make it testable. I can make it the same in V1 if approach is okay. There is one spec missing:\r\n\r\n```go\r\nfunc TestNastedCommandArgsPreparing(t *testing.T) {\r\n\tt.Parallel()\r\n\r\n\tcommand := \"ssh\"\r\n\targv := []string{\"ssh:info\"}\r\n\texpected := []string{\"deis-ssh info\"}\r\n\tactual := prepareCmdArgs(command, argv)\r\n\r\n\t// t.Errorf(\"Expected %v, Got %v\", reflect.TypeOf(expected), reflect.TypeOf(actual))\r\n\tif !reflect.DeepEqual(expected, actual) {\r\n\t\tt.Errorf(\"Expected %v, Got %v\", expected, actual)\r\n\t}\r\n}\r\n```\r\n\r\nI have got the following error:\r\n\r\n```\r\n--- FAIL: TestNastedCommandArgsPreparing (0.00s)\r\n    deis_test.go:88: Expected [deis-ssh info], Got [deis-ssh info]\r\n```\r\n\r\nBoth objects are `[]string` type. Not sure where the issue is."},"comment":{"url":"https://api.github.com/repos/deis/workflow-cli/issues/comments/250554637","html_url":"https://github.com/deis/workflow-cli/pull/255#issuecomment-250554637","issue_url":"https://api.github.com/repos/deis/workflow-cli/issues/255","id":250554637,"user":{"login":"deis-bot","id":7001982,"avatar_url":"https://avatars.githubusercontent.com/u/7001982?v=3","gravatar_id":"","url":"https://api.github.com/users/deis-bot","html_url":"https://github.com/deis-bot","followers_url":"https://api.github.com/users/deis-bot/followers","following_url":"https://api.github.com/users/deis-bot/following{/other_user}","gists_url":"https://api.github.com/users/deis-bot/gists{/gist_id}","starred_url":"https://api.github.com/users/deis-bot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deis-bot/subscriptions","organizations_url":"https://api.github.com/users/deis-bot/orgs","repos_url":"https://api.github.com/users/deis-bot/repos","events_url":"https://api.github.com/users/deis-bot/events{/privacy}","received_events_url":"https://api.github.com/users/deis-bot/received_events","type":"User","site_admin":false},"created_at":"2016-09-29T18:40:32Z","updated_at":"2016-09-29T18:40:32Z","body":"@Joshua-Anderson, @bacongobbler and @ultimateboy are potential reviewers of this pull request based on my analysis of `git blame` information. Thanks @smt116!"}}
{"actor":{"display_login":"deis-bot"}}