-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint.ts
More file actions
113 lines (111 loc) · 2.89 KB
/
print.ts
File metadata and controls
113 lines (111 loc) · 2.89 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { Command, parseCommand, ParseCommandError, type ICommand } from './index'
import { createCompletion } from './src/completion'
async function main(root: Command) {
try {
await parseCommand(Bun.argv.slice(2), root)
} catch (e) {
if (e instanceof ParseCommandError) {
console.log(`${e}`)
} else {
console.log(e)
}
}
}
function handler(args: string[], _: any, cmd: ICommand) {
console.log(cmd.name)
console.log(' - args:', args)
for (const item of cmd.flags) {
console.log(` - ${item.name}:`, item.value)
}
}
main(new Command({
name: 'main.ts',
usage: 'exampe flags',
prepare(flags) {
flags.int({
name: 'int',
short: 'i',
usage: 'example flag int',
})
flags.ints({
name: 'ints',
short: 'I',
usage: 'example flag int[]',
})
flags.uint({
name: 'uint',
short: 'u',
usage: 'example flag uint',
default: 80,
})
flags.uints({
name: 'uints',
short: 'U',
usage: 'example flag uint[]',
default: [80, 2052]
})
flags.string({
name: 'string',
short: 's',
usage: 'example flag string',
values: ['abc 123\"', 'def'],
})
flags.strings({
name: 'strings',
short: 'S',
usage: 'example flag string[]',
values: ['abc', 'def']
})
flags.bool({
name: 'bool',
short: 'b',
usage: 'example flag bool',
})
flags.bools({
name: 'bools',
short: 'B',
usage: 'example flag bool[]',
})
return handler
},
}).add(
{
name: 'child',
usage: 'subcommand example',
prepare(flags) {
flags.number({
name: 'number',
short: 'n',
usage: 'example flag number',
})
flags.numbers({
name: 'numbers',
short: 'N',
usage: 'example flag number[]',
values: [80, 443, 2052, 2053]
})
flags.bigint({
name: 'int',
short: 'i',
usage: 'example flag bigint',
})
flags.bigints({
name: 'ints',
short: 'I',
usage: 'example flag bigint[]',
})
flags.bool({
name: 'bool',
short: 'b',
usage: 'example flag bool',
})
flags.bools({
name: 'bools',
short: 'B',
usage: 'example flag bool[]',
})
return handler
}
},
createCompletion(),
))