icore
TypeScript 7 icore 3.0.2
A module for creating well-structured command-line interfaces in Node.js. Inspired by the concept of Clean Architecture.
Installation
Shell
npm install icore
Your first command
Define a hello command with --name and --uppercase options. Collect commands in a registry and pass it to createTerminalApp(). In the handle function, options.name is a string and options.uppercase is a boolean.
cli.ts
import { createCommand, createTerminalApp } from 'icore';
const command = createCommand();
const commands = command.registry([
command.define({
path: ['hello'],
options: {
name: {
type: 'string',
default: 'world'
},
uppercase: {
type: 'boolean',
default: false
}
},
handle({ options }) {
const greeting = `Hello, ${options.name}!`;
return `${options.uppercase ? greeting.toUpperCase() : greeting}\n`;
}
})
] as const);
const app = createTerminalApp({ commands });
async function main(args: readonly string[]): Promise<void> {
process.exitCode = await app.run(args, undefined, {
strict: true
});
}
void main(process.argv.slice(2));
After compiling cli.ts to dist/cli.js, the command prints HELLO, ALICE!.
Shell
node dist/cli.js hello --name Alice --uppercase
app.run(...) validates the arguments, runs the handler, and writes the result. With strict: true, the command name and subcommands must precede options.