Guided Tutorials
Build a CLI Tool with Rich Output
Create a command-line tool with argument parsing, colored output, progress bars, and help text.
What you'll learn
- How to design and scaffold a CLI tool with argument parsing and subcommands
- How to add colored output, spinners, and progress indicators
- How to test the tool locally with npm link before publishing
- How to package and distribute the tool via npm or a private registry
Before you start
- Autohand Code installed. Run
autohand --versionto confirm. See Your First Autohand Session if you need to install it. - Node.js 18 or newer. Run
node --versionto check. - An empty project directory. Create a new folder and run
npm init -yinside it.
Design the CLI
Before writing the prompt, sketch out what your tool should do. The more specific you are, the less back-and-forth you need after generation.
For a deployment readiness checker, think through:
- What checks should it run? Git status (no uncommitted changes), test suite passes, required environment variables are set.
- What is the command name and entry point? The binary will be called
deploy-check. - What should the output look like? A progress bar or spinner per check, green checkmark on pass, red X on fail, summary at the end.
- What flags does it need? Maybe
--env stagingto check a specific environment file, or--skip-teststo run faster. - What happens on failure? Exit with a non-zero code so CI pipelines can catch it.
Writing out this list takes two minutes and saves you multiple follow-up prompts.
Generate the tool
Run Autohand from your empty project directory with the prompt.
The agent scaffolds the project and installs dependencies. A typical run produces output like this:
The agent picks appropriate libraries. commander handles argument parsing, chalk handles colors, ora handles spinners, and execa runs subprocesses cleanly.
The generated structure
Here is what the generated project looks like.
The package.json bin field is what makes the tool installable as a global command. The entry point uses a Node.js shebang so it runs directly.
Each check is isolated in its own module. A check is a function that returns { passed: boolean, message: string }. This makes them easy to test and easy to add or remove.
Test it locally
Use npm link to install the tool as a global binary without publishing to npm.
Test the failure paths too. Introduce an uncommitted change and run the tool again to confirm the error output looks right.
Add more commands
Once the base tool works, extend it with subcommands. The agent keeps new commands consistent with the pattern it already generated.
Commander makes adding subcommands straightforward. The agent adds a .command('lint') block in src/index.js and creates a corresponding module in src/checks/.
Package and distribute
Once the tool is working the way you want, you have a few options for distribution.
Publish to npm so anyone can install it globally.
Add it as a dev dependency to a specific project so your team always has it available.
Install from a private registry or GitHub for internal tools that should not be public.
Tip: Ask Autohand to add a GitHub Actions workflow that tests the CLI on pull requests before you publish a new version.
What you learned
- Designed and generated a complete CLI tool with Commander, Chalk, and Ora
- Structured the project with isolated check modules and a clean entry point
- Tested the tool locally using npm link and verified both success and failure paths
- Extended the tool with subcommands, config files, and distribution options