Comments (7)
hey @jasonkarns do you have any good references or specific call-outs in the JS ecosystem of how to follow this one?
from nodejs-cli-apps-best-practices.
Unfortunately, I don't. commander
has no (or poor) support for completion, and I haven't found any cli utilities that provide it (yet). It's a bummer, because there are a load of cli utilities, and none that I'm aware of support completion out of the box. (Though it has been a while since I've looked.) The only resource I would point to is: https://github.com/scop/bash-completion but that's for registering completion scripts into the shell, not for helping create completion scripts.
from nodejs-cli-apps-best-practices.
Gotcha. I think it's more of a shell thing than the CLI itself so I'll close for now.
from nodejs-cli-apps-best-practices.
I don't think i'd go that far. In order to support shell completion, the CLI needs to do stuff.
Most integrations require the CLI to accept a flag (like --complete
or similar) which instructs the CLI to print to STDOUT all available options/args/subcommands. It must also be contextual, so that when a user has already provided a subcommand, the CLI only emits options/flags/further-subcommands that are relevant to what has already been typed thus far. (and to not emit flags that have already been passed)
Other times, the completion can be a standalone script; but to be sure it keeps sync with the features of the CLI, it must be owned and maintained by the CLI team itself. (3rd-party completion scripts are perpetually out of date because the CLI evolves without regard to keeping the completion script current)
Whether the CLI itself operates as the completion script (via a --complete
flag) or ships with a bundled completion script, in both cases the CLI owner is "responsible" for supporting completion capability.
from nodejs-cli-apps-best-practices.
Ahh interesting! is that --complete
thing documented anywhere?
from nodejs-cli-apps-best-practices.
No, it's mostly just a convention. The CLI needs to either:
- ship a standalone completion script that can be registered into the shell as the completion handler
- OR support a flag that can be wrapped by a function which is registered into the shell as the completion handler
Many CLI utilities ship a companion script for completion (if you're a homebrew/linuxbrew user, have a look at ls -al /usr/local/etc/bash_completion.d/ to see the completion scripts that homebrew installs for you). But all those completion scripts essentially boil down to invoking the shell complete
utility and registering a function to invoke when completion is necessary. It just so happens that a CLI can do double-duty as its own completion script if it looks for a particular flag and behaves as a completion script when the flag is present. It's only a minor convention that the flag itself be --complete
(since it's never typed by users by hand, the flag name itself is immaterial. As long as the correct flag is used when the registration is first done with the complete
utility).
from nodejs-cli-apps-best-practices.
Yep, I think this is a pretty decent practice to have. Less like the fact that it isn't cross-platform in an easy manner (standardization). I've seen evidence of only a few packages that handle this well, maybe just one (tabtab) on npmjs that is useful.
I'll re-open incase someone will want to pick it up.
from nodejs-cli-apps-best-practices.
Related Issues (20)
- How to perform user authentication in CLI? HOT 6
- Idea: add a section for CLI tools
- Updates needed for up to date Node.js runtime features
- Do you have plans to translate it into other languages? HOT 1
- New Practice: Distinguish STDOUT from STDERR
- Caveat: Accept STDIN somewhat counter to Empathetic CLI HOT 1
- Updating layout suggestions HOT 26
- Request: New experience best practice request: i18n HOT 2
- New Distribution Practice: Exclude unnesessary files from npm publish HOT 5
- GitLocalize: Problems with the structure of the .md file HOT 5
- Upgrade severals examples from require to import. HOT 1
- New Experience best practice request: version information HOT 7
- New feature: document other CLI related resources HOT 5
- New feature: document a new section for popular command line frameworks HOT 7
- Cleanup configuration files (if any) when uninstalling the package HOT 5
- Add the Crowdin internationalization integration tool to the project HOT 15
- remove 2.3 Cleanup configuration files chapter as it does not work since npm v7 HOT 2
- Can I use GitLocalize to translate documents? HOT 9
- Good first issue: add Crowdin badge to the repository
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nodejs-cli-apps-best-practices.