/
basic-usage.js
57 lines (53 loc) · 1.09 KB
/
basic-usage.js
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
const ArgsAndFlags = require('../index')
// node examples/basic-usage.js hi -m ok
const options = {
args: [
{
name: 'required-arg',
type: 'string',
help: 'an argument for saying hello',
required: true
},
{
name: 'hello',
type: 'string',
help: 'an argument for saying hello',
default: 'hey'
},
{
name: 'integer',
type: 'integer',
help: 'an integer argument',
default: 5
}
],
flags: [
{
name: 'toggle',
alias: 't',
type: 'boolean',
help: 'a boolean argument',
default: true
},
{
name: 'message',
alias: 'm',
type: 'string',
help: 'a string argument',
required: true
},
{
name: 'defaultValueFunction',
alias: 'd',
default: () => { return 'hi' },
type: 'string',
help: 'a string argument',
required: true
}
]
}
const parser = new ArgsAndFlags(options)
const { args, flags } = parser.parse(process.argv.slice(2))
console.log('args', args)
console.log('flags', flags)
console.log(parser.help())