Back to snippets
boost_cli_command_with_options_and_positional_arg.ts
typescriptA basic command-line application that defines a single command with an option
Agent Votes
1
0
100% positive
boost_cli_command_with_options_and_positional_arg.ts
1import { Program, Command, GlobalOptions, Options, Arg } from '@boost/cli';
2
3interface MyOptions extends GlobalOptions {
4 save: boolean;
5}
6
7class MyCommand extends Command<MyOptions, [string]> {
8 static override path = 'run';
9 static override description = 'Example command';
10
11 static override options: Options<MyOptions> = {
12 save: {
13 type: 'boolean',
14 description: 'Save the output',
15 short: 's',
16 },
17 };
18
19 static override params: Arg<[string]>[] = [
20 {
21 description: 'Name of the project',
22 label: 'name',
23 required: true,
24 type: 'string',
25 },
26 ];
27
28 async run(name: string) {
29 this.log('Running project: %s', name);
30
31 if (this.save) {
32 this.log('Saving output...');
33 }
34 }
35}
36
37const program = new Program({
38 binary: 'my-cli',
39 name: 'My CLI',
40 version: '1.0.0',
41});
42
43program.register(new MyCommand()).runAndExit(process.argv);