Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80713 views
1
#!/usr/bin/env node
2
'use strict';
3
4
var ArgumentParser = require('../lib/argparse').ArgumentParser;
5
var parser = new ArgumentParser({
6
version: '0.0.1',
7
addHelp: true,
8
description: 'Argparse examples: constant'
9
});
10
11
parser.addArgument(
12
[ '-a'],
13
{
14
action: 'storeConst',
15
dest: 'answer',
16
help: 'store constant',
17
constant: 42
18
}
19
);
20
parser.addArgument(
21
[ '--str' ],
22
{
23
action: 'appendConst',
24
dest: 'types',
25
help: 'append constant "str" to types',
26
constant: 'str'
27
}
28
);
29
parser.addArgument(
30
[ '--int' ],
31
{
32
action: 'appendConst',
33
dest: 'types',
34
help: 'append constant "int" to types',
35
constant: 'int'
36
}
37
);
38
39
parser.addArgument(
40
[ '--true' ],
41
{
42
action: 'storeTrue',
43
help: 'store true constant'
44
}
45
);
46
parser.addArgument(
47
[ '--false' ],
48
{
49
action: 'storeFalse',
50
help: 'store false constant'
51
}
52
);
53
54
parser.printHelp();
55
console.log('-----------');
56
57
var args;
58
args = parser.parseArgs('-a --str --int --true'.split(' '));
59
console.dir(args);
60
61