cli-template-js
v0.0.3
Published
A template for creating CLIs with TypeScript
Readme
cli-template
A minimal Bun CLI template using Commander, Chalk & Inquirer.
Usage
# Run locally
bun src/cli.ts --help
# Dev script
bun run devCommands
greet <name> Greet someone
interactive|i Launch an interactive prompt session
split <string> Split a string into parts
spinner Show a spinner animationGlobal install
The bin field in package.json points to src/cli.ts with a #!/usr/bin/env bun shebang, so the CLI can be installed globally:
# Install globally from local
bun install -g .
# Or link for development
bun link
# Or install from npm once published
bun install -g cli-templateOnce installed, run from anywhere:
cli-template greet World
cli-template split "a,b,c" --firstYou can also use it ad-hoc without installing:
bunx cli-template greet WorldInteractive prompts
The interactive command uses Inquirer for rich terminal prompts:
import inquirer from 'inquirer';
const answers = await inquirer.prompt([
{
type: 'input',
name: 'name',
message: 'What is your name?',
default: 'World',
},
{
type: 'select',
name: 'color',
message: 'Pick a color:',
choices: ['Red', 'Green', 'Blue', 'Yellow'],
},
{
type: 'confirm',
name: 'shout',
message: 'Shout it?',
default: false,
},
]);
console.log(`Hello, ${answers.name}! Your color is ${answers.color}.`);Run it:
bun src/cli.ts interactive
# or
bun run dev interactive