HerokuCasey WattsTutorial
CLI Flags in Practice + How to Make Your Own CLI Command with oclif
Summary
CLI commands commonly accept arguments, long flags, short flags, and flag arguments; environment variables and standard input are alternative data channels not covered in detail. GNU-style conventions use double dashes for long flags and single dashes for short flags; short flags can be stacked, and flag options may be separated by a space or equals sign, while short flags also allow no separator. The tutorial uses oclif to build greet-me, which prints a greeting based on a name supplied through -n or --name while registering version, help, name, and force flags. It scaffolds the project with npx oclif single greet-me, places handling code in src/index.ts, defaults the name to world, and runs the CLI through ./bin/run or an npm link.
Context
CLI parameters can be difficult to understand and design ergonomically. The material introduces the common parts of a command so users can make fewer typos and understand shared commands more quickly, while CLI designers can create clearer user interfaces.
Approach / What changed
It explains arguments, long and short flags, flag arguments, and their syntax using ls, tar, and git examples, then scaffolds a greet-me CLI with npx oclif single greet-me. The implementation registers flags in an oclif command class, defaults the name to world, and runs the CLI directly or through npm link.
Takeaways
Long flags use two dashes and multiple characters, while short flags use one dash and one letter; short flags can be stacked, as in ls -la.
A flag option must immediately follow the flag and can be separated by a space or equals sign; short flags may also attach the option directly, as in tar -farchive.tar.
The generated oclif command registers version, help, name, and force flags, and its name flag supports both -n and --name forms.
Source and freshness
- Source
- heroku.com
- Published
- Added to Yomu
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.