-
Notifications
You must be signed in to change notification settings - Fork 6
/
cli.js
98 lines (97 loc) · 2.44 KB
/
cli.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
98
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
export const cli = (main) => {
yargs(hideBin(process.argv))
.scriptName('qrpwd')
.usage('$0 <command> [options]')
.command(
'encode',
'Create a QR code with encoded data',
(yargs) => {
yargs
.option('m', {
alias: 'message',
type: 'string',
description: 'Message to encode',
})
.option('d', {
alias: 'debug',
type: 'boolean',
default: false,
description: 'Enable debug mode for error reporting',
})
.option('i', {
alias: 'input',
type: 'string',
description: 'Input file to encode',
})
.option('p', {
alias: 'password',
type: 'string',
description: 'Password to encrypt data',
})
.option('s', {
alias: 'silent',
type: 'boolean',
default: false,
description: '',
})
.option('o', {
alias: 'output',
type: 'string',
default: () =>
new Date().toISOString().replace(/[:.]/g, '-') + '.qr.png',
description: 'Output QR code file',
})
.option('u', {
alias: 'unprotected',
type: 'boolean',
default: false,
description: 'Do not use password protection',
});
},
main
)
.command(
'decode',
'Decode data from a QR code',
(yargs) => {
yargs
.option('i', {
alias: 'input',
type: 'string',
demandOption: true,
description: 'Input QR code file',
})
.option('d', {
alias: 'debug',
type: 'boolean',
default: false,
description: 'Enable debug mode for error reporting',
})
.option('p', {
alias: 'password',
type: 'string',
description: 'Password to decrypt data',
})
.option('s', {
alias: 'silent',
type: 'boolean',
default: false,
description: '',
})
.option('o', {
alias: 'output',
type: 'string',
default: () =>
new Date().toISOString().replace(/[:.]/g, '-') + '.txt',
description: 'Output decoded data file',
});
},
main
)
.demandCommand(1, 'You must provide a valid command')
.help()
.alias('h', 'help')
.argv;
};