{"action":"created","issue":{"url":"https://api.github.com/repos/yeoman/yo/issues/426","repository_url":"https://api.github.com/repos/yeoman/yo","labels_url":"https://api.github.com/repos/yeoman/yo/issues/426/labels{/name}","comments_url":"https://api.github.com/repos/yeoman/yo/issues/426/comments","events_url":"https://api.github.com/repos/yeoman/yo/issues/426/events","html_url":"https://github.com/yeoman/yo/pull/426","id":152466802,"number":426,"title":"Add completion based on env.getGeneratorsMeta() and --help","user":{"login":"mklabs","id":113832,"avatar_url":"https://avatars.githubusercontent.com/u/113832?v=3","gravatar_id":"","url":"https://api.github.com/users/mklabs","html_url":"https://github.com/mklabs","followers_url":"https://api.github.com/users/mklabs/followers","following_url":"https://api.github.com/users/mklabs/following{/other_user}","gists_url":"https://api.github.com/users/mklabs/gists{/gist_id}","starred_url":"https://api.github.com/users/mklabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mklabs/subscriptions","organizations_url":"https://api.github.com/users/mklabs/orgs","repos_url":"https://api.github.com/users/mklabs/repos","events_url":"https://api.github.com/users/mklabs/events{/privacy}","received_events_url":"https://api.github.com/users/mklabs/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2016-05-02T00:59:48Z","updated_at":"2016-05-10T09:36:07Z","closed_at":"2016-05-08T20:18:05Z","pull_request":{"url":"https://api.github.com/repos/yeoman/yo/pulls/426","html_url":"https://github.com/yeoman/yo/pull/426","diff_url":"https://github.com/yeoman/yo/pull/426.diff","patch_url":"https://github.com/yeoman/yo/pull/426.patch"},"body":"This is an attempt at fixing #222 \r\n\r\n## Proposal\r\n\r\nThis PR implements autocompletion feature based on `env.getGeneratorsMeta()` from `yeoman-environment`. It uses [tabtab](https://www.npmjs.com/package/tabtab) and [parse-help](https://www.npmjs.com/package/parse-help) to provide completions for bash, zsh and fish shells.\r\n\r\nCompletion against `yo <tab>` should complete the list of available generators and options like `--force` or `--generators`.\r\n\r\n![yo-complete](https://camo.githubusercontent.com/bc7f339383b73aadee239a7e6b081752290b3254/687474703a2f2f692e696d6775722e636f6d2f4c51597843625a2e706e67)\r\n\r\n![yo-complete](https://i.imgur.com/IPSLcfO.png)\r\n\r\nCompleting after a generator or subgenerator `yo generator <tab>` should complete relevant options from the generator `--help` output\r\n\r\n![yo-complete](https://camo.githubusercontent.com/c4427238e4e2fd58bf9feaa85932b8c243f02272/68747470733a2f2f692e696d6775722e636f6d2f7a6470446e41332e706e67)\r\n\r\n## Detail\r\n\r\n### yo-complete\r\n\r\nThis PR introduces a new command, `yo-complete` which acts like `npm completion`. Its sole role is to output to STDOUT completion candidates whenever the user triggers completion.\r\n\r\nThis is done using a shell script specific to the user environment (bash, zsh or fish) that invokes `yo-complete` with the state of the command line (line, words and cursor position). `yo-complete` then asks yeoman environment the list of installed generators, and parses help output for generators / sub generators using parse-help.\r\n\r\n### options\r\n\r\nOptions like `--force` etc. are defined within the package.json `tabtab` property.\r\n\r\n```json\r\n  \"tabtab\": {\r\n    \"yo\": [\r\n      \"-f\",\r\n      \"--force\",\r\n      \"--version\",\r\n      \"--no-color\",\r\n      \"--no-insight\",\r\n      \"--insight\",\r\n      \"--generators\"\r\n    ]\r\n  }\r\n```\r\n\r\nThis list is used alongside the generator list returned by getGenratorsMeta().\r\n\r\n### Installation\r\n\r\nThere's a way to automatically install and enable shell completion on `npm install yeoman -g`, using package.json `install` script and calling `tabtab install` right after `yo doctor`.  Otherwise, it requires a manual additional step for the user (like `tabtab install --stdout >> ~/.bashrc`)\r\n\r\nThe default behavior is to use Inquirer to prompt the user for installation instruction, answers are based on the user `$SHELL`:\r\n\r\n![install](https://raw.githubusercontent.com/mklabs/node-tabtab/master/docs/img/zsh-install.png)\r\n\r\nIt implies having prompts on yeoman installation that requires user interaction, which you might want to avoid.\r\n\r\n---\r\n\r\nAre you guys still interested in this ? This is something we started to discuss a long time ago. The difficulty of getting the list of globally installed generators was the main obstacle back then, but now nicely handled by yeoman-environment and getGeneratorsMeta()\r\n\r\nThe completion of options for generators / subgenerators is pretty generic, and use parse-help to automatically discover them but we might think of exposing some kind of API for generators to have better control on what's get completed.\r\n\r\nIf you're 👍 for that, I'll check in a few test case to cover `yo-complete` behavior, there's a basic `npm run test-completion` script for the moment.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/yeoman/yo/issues/comments/218107361","html_url":"https://github.com/yeoman/yo/pull/426#issuecomment-218107361","issue_url":"https://api.github.com/repos/yeoman/yo/issues/426","id":218107361,"user":{"login":"nwinkler","id":907063,"avatar_url":"https://avatars.githubusercontent.com/u/907063?v=3","gravatar_id":"","url":"https://api.github.com/users/nwinkler","html_url":"https://github.com/nwinkler","followers_url":"https://api.github.com/users/nwinkler/followers","following_url":"https://api.github.com/users/nwinkler/following{/other_user}","gists_url":"https://api.github.com/users/nwinkler/gists{/gist_id}","starred_url":"https://api.github.com/users/nwinkler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nwinkler/subscriptions","organizations_url":"https://api.github.com/users/nwinkler/orgs","repos_url":"https://api.github.com/users/nwinkler/repos","events_url":"https://api.github.com/users/nwinkler/events{/privacy}","received_events_url":"https://api.github.com/users/nwinkler/received_events","type":"User","site_admin":false},"created_at":"2016-05-10T09:36:07Z","updated_at":"2016-05-10T09:36:07Z","body":"While I really like the idea of having completion, this new feature threw me off during automated installation (using Ansible). Since `tabtab` asks the user where the completion is supposed to be installed, this step stalls the automated install.\r\n\r\nIt took me a good bit of digging to find that I can set the `CI` environment variable to avoid the `tabtab` execution.\r\n\r\nIn addition to that, I find the whole thing a bit intrusive. This is the only tool installed through `npm` that I know of that asks the user for additional information during the installation. Not sure whether you want to change that, but I prefer silent installation as a default. Is the question on where to install the completion files really necessary - can't we just use a meaningful default and avoid the question for the user?\r\n"}}