1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
// commands.ts
import {
command,
run,
string,
positional,
restPositionals,
boolean,
flag,
} from "cmd-ts";
const app = command({
name: "app",
args: {
debug: flag({
long: "debug",
short: "d",
type: boolean,
description: "Enable debug mode",
defaultValue: () => false,
}),
first: positional({ type: string, displayName: "first arg" }),
rest: restPositionals({ type: string, displayName: "rest" }),
},
handler: ({ debug, first, rest }) => {
console.log({ debug });
console.log({ first });
console.log({ rest });
},
});
run(app, process.argv.slice(2));
|
1
| ts-node commands.ts 2>&1
|
error: found 1 error
1. No value provided for first arg
hint: for more information, try 'app --help'
1
| ts-node commands "first argument"
|
{ debug: false }
{ first: 'first argument' }
{ rest: [] }
1
| ts-node commands "first argument" -d everything else that i put in here
|
{ debug: true }
{ first: 'first argument' }
{ rest: [ 'everything', 'else', 'that', 'i', 'put', 'in', 'here' ] }