-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic-example.ts
More file actions
60 lines (56 loc) · 1.43 KB
/
basic-example.ts
File metadata and controls
60 lines (56 loc) · 1.43 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
#!/usr/bin/env bun
import { createCLI, createCommand } from '../src/index.ts';
const cli = createCLI({
name: 'example-cli',
version: '1.0.0',
description: 'A simple example CLI',
commands: {
greet: createCommand({
name: 'greet',
description: 'Greet someone',
examples: [
'greet World',
'greet "John Doe" --excited',
'greet Alice --times 3'
],
options: {
excited: {
type: 'boolean',
description: 'Add excitement to the greeting'
},
times: {
type: 'number',
description: 'Number of times to greet',
default: 1
}
},
execute: ({ args, options }) => {
const name = args[0] || 'World';
const greeting = options.excited ? `Hello ${name}!!!` : `Hello ${name}`;
for (let i = 0; i < options.times; i++) {
console.log(greeting);
}
}
}),
echo: createCommand({
name: 'echo',
description: 'Echo the input',
examples: [
'echo "Hello World"',
'echo test --uppercase'
],
options: {
uppercase: {
type: 'boolean',
description: 'Convert to uppercase'
}
},
execute: ({ args, options }) => {
const text = args.join(' ');
console.log(options.uppercase ? text.toUpperCase() : text);
}
})
}
});
// Run the CLI
cli.run().catch(console.error);