Building CLI based on Command Pattern.
clibuilder-testutil
contains test utilities to help you test against your application.
// bin.ts
import { Cli } from 'clibuilder'
import { commandA, commandB } from './commands'
const cli = new Cli('yourcli', '1.0.0', [commandA, commandB])
cli.parse(process.argv)
// commands.ts
import { CommandSpec } from 'clibuilder'
export const commandA = {
name: 'echo',
// `args` is the parsed minimist args.
// `argv` is the raw argv.
run(args, argv) {
this.ui.info(argv)
}
} as CommandSpec
You can override the display mechanism:
import { Cli, PlainPresenter } from 'clibuilder'
class YourPresenter extends PlainPresenter { ... }
const presenterFactory = {
createCliPresenter(options) { return new YourPresenter(options) },
createCommandPresenter(options) { return new YourPresenter(options) }
}
const cli = new Cli('yourcli', '1.0.0', [], { presenterFactory })
cli.parse(process.argv)
# right after fork
npm install
# begin making changes
npm run watch