npm i ts-commands
Create a command file:
src/bin/greet-command.ts
import { Command, OptionType } from '../src';
interface Args {
fname: string;
lname: string;
informal?: boolean;
}
export class GreetCommmand extends Command {
signature = 'greet [fname] [lname]';
description = 'say hello';
positional = [
{
key: 'fname',
type: OptionType.string,
description: 'first name',
default: 'Tom',
},
{
key: 'lname',
type: OptionType.string,
description: 'last name',
default: 'Tester',
},
];
options = [
{
key: 'informal',
type: OptionType.boolean,
default: false,
description: 'Informal?',
},
];
async handle(args: Args) {
const greeting = args.informal ? 'yo' : 'hello';
console.log(`${greeting} ${args.fname} ${args.lname}`);
}
}
Create an index file to register your command(s):
src/bin/index.ts
import { registerCommands } from 'ts-commands';
import { GreetCommmand } from './greet-command';
registerCommands({
name: 'examples',
commands: [GreetCommmand],
});
- Repeat "Creating Commands" section for each command
- Add each command in the
commands
array ofregisterCommands