Skip to content
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

Tab completion? #385

Closed
bitjson opened this issue Mar 29, 2015 · 18 comments
Closed

Tab completion? #385

bitjson opened this issue Mar 29, 2015 · 18 comments

Comments

@bitjson
Copy link

bitjson commented Mar 29, 2015

Has anyone implemented tab completion with commander? Complete looks like a working module, but it seems like this would be perfect territory for commander.

Another module: completion

@okv
Copy link

okv commented Jun 22, 2015

It would be great to have shell auto-completion for already generated program help without write much code. Suggestions? I can't find anything suitable at npm.

@zhiyelee
Copy link
Collaborator

Interesting. PR about this feature is welcome~

@okv
Copy link

okv commented Jun 23, 2015

E.g.:

  • if input starts with - then autocomplete global options and command options (if command is already typed)
  • if you don't yet choose a command - suggest commands
  • allow to extend/override autocompletion behaviour programmatically (to suggest custom parameters for options (as branches in git), etc)

@arthurafarias
Copy link

This would be a great feature. =D

@thethomaseffect
Copy link
Collaborator

I looked into this in the past and had a working prototype (not using a third party module). However, getting it working for windows is a whole other ballgame. I'd like to see a powershell solution so commander can continue to be multi-platform

@plusmancn
Copy link

I have found commander-auto-complete, but which is not good enough to use for product.

@tonylukasavage
Copy link
Contributor

Windows support has been one of the reasons in the past that I never pursued this personally. That, and the fact that I think a solid usage doc with a levenshtein distance check on attempted command executions (like git) usually covers the case. IMHO, I feel like if you're leaning on autocomplete for your CLI, you might have a design issue with it. Not to say that they're aren't real cases that could use it, but I'm of the opinion they should be rare.

@bitjson
Copy link
Author

bitjson commented Jun 30, 2016

Just an update on this – those looking for CLI auto-completion might want to consider switching to Vorpal. Vorpal is a bit more involved, but it has a lot of the more advanced features built-in.

@k0pernikus
Copy link

@bitjson Vorpals autocompletion is quite awesome, yet the lack of typescript typings is a dealbreaker for me. Yet commander has them.

I wished commander would also support autocompletion :)

@atheros
Copy link

atheros commented Apr 11, 2017

@tonylukasavage don't dismiss autocompletion as being a quick fix for poor design decisions. It can also be user for values for example:

addpermission user@... system.admin system....

Many database CLIs implement this kind of autocomplete for table names and fields.

@bitjson Vorpal works great as a shell, however due to some bugs, it's pretty much impossible to invoke a single command from command line and quit

@BafS
Copy link

BafS commented Nov 5, 2017

An alternative is also Yargs: https://github.com/yargs/yargs

@bitjson
Copy link
Author

bitjson commented Mar 8, 2019

For anyone following this issue, I strongly recommend you check out oclif.

It's extremely well-designed, and the autocompletion is fantastic.

@shadowspawn
Copy link
Collaborator

@bencao has done an integration with Omelette in #907, but it was decided not to include it in Commander itself at this time.

@shadowspawn
Copy link
Collaborator

Not currently planning to build tab completion into Commander itself, so closing this issue.

I am interested in this as a problem, so please let us know about packages which integrate well with Commander.

@keidrych
Copy link

keidrych commented Mar 7, 2023

Leaving breadcrumbs for anyone who is wanting to get this up and running simply:

hello.js

const {Command} = require('commander')
const omelette = require('omelette')
const process = require('node:process')

const cli = new Command('hello')
omelette('hello').tree({
  cruel: ['world']
  beautiful: ['mars']
}).init()

if (!~process.argv.indexOf('--completion')) {
  cli.command('cruel')
  cli.command('beautiful')
}
cli.parse()

to make it work source omelette output to your shell and alias as explained in omelette documentation

source <(node hello.js --completion)
alias hello='nodejs hello.js'

Then just hello etc...

@gagregrog
Copy link

gagregrog commented Feb 4, 2024

Leaving breadcrumbs for anyone who is wanting to get this up and running simply:

This was very helpful to get things started, thank you! I'd like to point out one thing in case others are initially unable to get this example working.

First, add a comma after cruel: ['world'] 😉.
Secondly, if you are running this with zsh it will not work. The alias will not work with tab completion, but it does work if you wrap it in a function:

hello() {
    node index.js $@
}

source

@KaKi87
Copy link

KaKi87 commented Mar 8, 2024

Hi,
Did anyone implement commander autocompletion with node:repl ?
Thanks

@jchook
Copy link

jchook commented Sep 25, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.