1.0.2 • Published 4 months ago
kuri-cli v1.0.2
Kuri
Kuri is a modern, IoC-style CLI framework written in TypeScript that empowers developers to build elegant, scalable, and maintainable command-line applications.
Features
- Decorator-based API - Define commands, options, and arguments using TypeScript decorators
- Dependency Injection - Built-in IoC container with constructor and property injection
- Type Safety - Leverage TypeScript's type system for better development experience
- Modular Architecture - Split CLI applications into multiple commands and modules
- Extensible Design - Easily extensible for adding custom functionality
- Zero Configuration - Works out of the box with sensible defaults
Installation
# Using npm
npm install kuri-cli
# Using yarn
yarn add kuri-cli
# Using pnpm
pnpm add kuri-cli
Quick Start
import 'reflect-metadata';
import { Kuri, Command, Option, Action } from 'kuri-cli';
@Command({
name: 'greet',
description: 'Greet a person'
})
class GreetCommand {
@Option('-n, --name <name>', 'Name to greet', 'World')
private name: string;
@Action()
public execute(): void {
console.log(`Hello, ${this.name}!`);
}
}
async function main() {
const kuri = new Kuri({
name: 'my-cli',
version: '1.0.0',
commands: [GreetCommand]
});
await kuri.parseAsync(process.argv);
}
main().catch(console.error);
Run your CLI:
$ ts-node index.ts greet --name Developer
Hello, Developer!
Core Concepts
Command
Use the @Command
decorator to define CLI commands:
@Command({
name: 'serve',
description: 'Start the server',
aliases: ['start', 's']
})
class ServeCommand {
// ...
}
Options
Use @Option
and @RequiredOption
decorators for command options:
@Option('-p, --port <port>', 'Port number', '3000')
private port: string;
@RequiredOption('-c, --config <path>', 'Config file path')
private configPath: string;
Arguments
Use the @Argument
decorator for positional arguments:
@Argument('file', 'File to process', 'default.txt')
private file: string;
Action
Mark the method to execute when the command runs using @Action
:
@Action()
public execute(): void {
// Command implementation
}
Dependency Injection
Kuri provides built-in dependency injection through Inversify:
@Injectable()
class ConfigService {
public getConfig(): object {
return { /* config */ };
}
}
@Command({ name: 'start' })
class StartCommand {
constructor(@Inject(ConfigService) private config: ConfigService) {}
@Action()
execute() {
const config = this.config.getConfig();
// Use config...
}
}
// Register service in container
const kuri = new Kuri({
name: 'my-cli',
version: '1.0.0',
commands: [StartCommand],
});
Examples
Check the examples directory for more examples