ts-commands
v1.1.0
Published
ts-commands
Downloads
28
Maintainers
Readme
ts-commands - Readme
Installation
npm i ts-commands
Creating 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}`);
}
}
Register Commands
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],
});
Create Additional Commands
- Repeat "Creating Commands" section for each command
- Add each command in the
commands
array ofregisterCommands