-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.js
executable file
·97 lines (89 loc) · 2.23 KB
/
demo.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
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
/* eslint-disable spellcheck/spell-checker */
import argi from './src/argi';
// Uncomment to remove default help behavior
// delete argi.defaults.flags.help;
// Uncomment to change default versionText
// argi.versionText = 'VERSION: 9001';
argi.helpText = `This is a test of your emergency preparedness systems. Please do not be alarmed!\n\n--------------------------`;
argi.defaults.transform.csv = value => value.split(',');
argi.registerOptions({
__subCommands: [
{
name: 'operation',
required: true,
test: value => /get|set/.test(value) || `"${value}" is not a supported operation .. Use "get" or "set"`,
description: 'Get or set the things',
},
{
name: 'force',
description: 'Force the operation',
},
],
__tail: [
{
name: 'source',
description: 'The source file path',
},
{
name: 'files',
rest: true,
description: 'Any number of space separated target file paths',
},
],
simpleString: {
alias: 's',
description: 'A simple string flag test',
},
stringArr: {
description: 'A an array of strings provided with N flags',
transform: value => (argi.options.str ? argi.options.str.concat(value) : [value]),
},
string: {
defaultValue: 'default',
alias: 'S',
variableName: 'helpfulName',
transform: value => value.toUpperCase(),
description: 'A complex string flag test',
},
});
const { options } = argi.parse({
number: {
type: 'number',
required: true,
test: value => value > 10 || '--number requires a value greater than 10',
alias: ['n', 'num'],
description: 'A simple number flag test',
},
list: {
type: 'csv',
description: 'A simple csv list flag test',
},
bool: {
type: 'boolean',
description: 'A simple boolean flag test',
},
complexBoolean: {
type: 'boolean',
alias: ['c', 'B', 'cBool'],
defaultValue: true,
transform: value => `${value ? 'T' : 'Not t'}o be`,
description: 'A complex boolean flag test',
},
});
// Uncomment for a simple test
// const { options } = argi.parse({
// str: {
// alias: 's'
// },
// num: {
// type: 'number',
// alias: 'n'
// },
// bool: {
// type: 'boolean',
// alias: 'b'
// }
// });
console.log('Passthrough Args', argi.passThrough);
console.log('Unparsed Args', argi.argArray);
console.log('Options', options);