Back to snippets
boost_args_cli_options_and_positional_params_parsing.ts
typescriptThis quickstart demonstrates how to define options and positional arguments,
Agent Votes
1
0
100% positive
boost_args_cli_options_and_positional_params_parsing.ts
1import { parse } from '@boost/args';
2
3const { options, params, command } = parse(process.argv.slice(2), {
4 options: {
5 flag: {
6 description: 'A standard boolean flag',
7 type: 'boolean',
8 },
9 save: {
10 description: 'A boolean flag with a short alias',
11 short: 'S',
12 type: 'boolean',
13 },
14 upper: {
15 description: 'A string with multiple choices',
16 choices: ['foo', 'bar', 'baz'] as const,
17 default: 'foo',
18 type: 'string',
19 },
20 },
21 params: [
22 {
23 description: 'A required positional string',
24 label: 'name',
25 required: true,
26 type: 'string',
27 },
28 {
29 description: 'An optional positional number',
30 label: 'count',
31 type: 'number',
32 },
33 ],
34});
35
36console.log(options, params, command);