-
-
Notifications
You must be signed in to change notification settings - Fork 399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Completion: Silent install, better handling of descriptions #442
Conversation
Implement generator / flags description completion: remove help output parsing, too slow / unreliable , will probably try to figure out options / arguments from generator instead. review: use babel default plugin export review: update help for completion command completion: npm hooks to install / uninstall tabtab, silently completion: update tabtab version
@SBoudrias node v0.10 fails on travis because of https://travis-ci.org/yeoman/yo/jobs/131948386#L190 not sure how to fix it, or if I should. Let me know, this PR fixes an important bug as reported in #441 If you'd like more time to review, a bump to package.json to force install of [email protected] instead of [email protected], that was just published should fix it as well. |
Should really just remove |
"read-pkg-up": "^1.0.1", | ||
"repeating": "^2.0.0", | ||
"root-check": "^1.0.0", | ||
"sort-on": "^1.0.0", | ||
"string-length": "^1.0.0", | ||
"tabtab": "^1.3.0", | ||
"tabtab": "1.4.x", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep using ^
range. The issue you had with 1.4 is that you published a breaking change without a major version bump which broke npm semver reliance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I know :/
I was't aware it was a breaking change, and really don't want to bump a major version because of a misconfigured Babel and yo integration (this .default
thing ..)
I'll keep at that way (using range
) and will publish [email protected] alongside this pull request.
About node 0.10, you can use |
@SBoudrias I'll see if I can add btw, would it be better / safer change the target branch of this PR to a feature branch on yeoman repo ? I'd recommend merging this request (when good to merge) in a specific branch where contributors and users willing to give feedback on the completion system can do. I'd like to avoid introducing issues for peoples that don't care about this completion thing. I've spent a lot of energy on this already, and feel there is still more work to do. This is quite tricky due to the 3 different shell environments, and kinda hard to test (that's whay any feedbacks / bug reports on this is really important to me). |
Usually that's kind of useless as we end up getting no feedback at all. We should merge on master, but make sure we're failing gracefully. |
Okay. Let's use this PR to extensively test it out, on different shells etc. I still have this bash bug with ":" character a bit tricky to fix: mklabs/tabtab#22 (occurs with generator:subgenerator) |
@binduwavell did some great testing and provided amazing feedbacks. Good progress. zsh is confirmed to work way better. We'll next try to work on the generator completion, eg.
We were thinking about some kind of API for generator authors to be able to customize the completion.
"tabtab": ['--flag', '--name', ... ]
// extended with completion description (fish / zsh)
"tabtab": [
// flags
{ name: '--name', description: 'Name definition for the ... Model'},
{ name: '--template', description: 'Template engine to use with view generator'},
// arguments (subgenerators)
{ name: 'view', description: 'Create a new model for your application'}
{ name: 'model', description: 'Create a new model for your application'}
]
// in package.json
"tabtab": "lib/completions.js"
// lib/completions.js
module.exports = function (data, done) {
// yo generator foo <tab>
data.line; // line value for the completed command: yo generator foo
data.prev; // value of the previous word: foo
data.cursor; // number cursor position: 17
return done(null, ['--help', '--name', ...]);
};
// possibly use promise
module.exports = function (data) {
// yo generator foo <tab>
data.line; // line value for the completed command: yo generator foo
data.prev; // value of the previous word: foo
data.cursor; // number cursor position: 17
return new Promise(function(resolve, reject) {
resolve(['--help', '--name', ...]);
});
}; @SBoudrias @sindresorhus @kevva Let us know what you think. Particularly on this completion API for generator authors. Would love more feedbacks :) Thanks! |
I like the latter. It gives maximum flexibility and completions are rarely only static. |
I don't see how the first option will work when main generator and sub generators have different options and arguments. If we can nest completion definitions that could be nice. I agree that the second option would be better. If we go that route, it would be nice if data could include some yeoman specific properties: subgenerator at least. I suspect we could do better by generalising handling of: subgenerator names, positional argument awareness, option and option aliases, vales by type and singular vs multi valued values. Maybe fall back to this proposal for folks that need ultimate control. In my generators, I have tied arguments and options to prompts and can run the filter function from the prompt on values provided via the commandline, would be nice to be able to plug that in to completion as well. With the completion function being a standalone module, I would likely have to duplicate a bunch of specification. I'd love to be able to have the choices for a prompt drive the completion values for an argument or option. |
I'd like to see both options implemented. If "tabtab" package.json value is a string, require the file and use the handler, if it's an Array, then register the completion results directly. Good idea on providing yeoman specific info like subgenerator. A third option like you described would be to require a given generator and inspect this.arguments / this.options to build completions automatically from these. |
I feel options and arguments are relevant information for any person implementing another adapter for our generators. I think we should go with a generic option. Right now you're loading a generator an inspecting the results of the |
Generalized option completion for tabtab
@mklabs @binduwavell I see some commits have been added on top of the last PR. What is the state currently, is this in a working state? |
Hi @SBoudrias No i dont think so. There is still a few things to test out. If you'd like to see how well it behaves ans provide us feedbacks, you could fetch and check in the approriate branch. |
I'm going to close this long running pull request for the moment, I might reopen and rework on it at a latter time. |
Follow up to the completion feature.
This PR tries to implement what we discussed before, and fix a few issues we had for bash / zsh shell (mklabs/tabtab#21)
--auto
for bothinstall / uninstall
. It'll use the shell configuration file without prompting user for a decision. It goes in pair withtabtab uninstall --auto
npm i yo -g
andnpm uninstall yo -g
will automatically update the SHELL configuration file (~/.bashrc, ~/.zshrc or ~/.config/fish/config.fish). This should be totally transparent.yo generator <tab>
completion where we try to parse the help output. I got a lot of issues with it, and decided to put it aside for the moment. Plus, the--help
output exec is really slow and not ideal. I'm thinking about trying to require the generator and try to see if I can inspect the options / arguments hash.Question: While implementing descriptions, I wondered what we should set as description for flags and generators. For now I went for
%subgenerator from %name generator
, if you can think of something better 👍