-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathindex.ts
39 lines (33 loc) Β· 760 Bytes
/
index.ts
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
/**
* Demo from README.md
*
* Usage:
* npx esno examples/greet --help
*/
import { cli } from '../../src';
// Parse argv
const argv = cli({
name: 'greet.js',
// Define parameters
// Becomes available in ._.filePath
parameters: [
'<first name>', // First name is required
'[last name]', // Last name is optional
],
// Define flags/options
// Becomes available in .flags
flags: {
// Parses `--time` as a string
time: {
type: String,
description: 'Time of day to greet (morning or evening)',
default: 'morning',
},
},
});
const name = [argv._.firstName, argv._.lastName].filter(Boolean).join(' ');
if (argv.flags.time === 'morning') {
console.log(`Good morning ${name}!`);
} else {
console.log(`Good evening ${name}!`);
}