-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscratch.js
56 lines (49 loc) · 1.48 KB
/
scratch.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
const Cmr1Cli = require('./lib/cli')
const additionalOptions = [
{
name: 'src',
alias: 's',
type: String,
multiple: true,
defaultOption: true,
description: 'Input source',
typeLabel: '[underline]{file}'
},
{
name: 'timeout',
alias: 't',
type: Number,
description: 'Timeout',
typeLabel: '[underline]{ms}'
}
]
const myCli = new Cmr1Cli({
name: 'My CLI script name',
description: 'A description of this script',
helpHeader: 'Available Options',
optionDefinitions: additionalOptions,
logging: {
test: {
verbose: true, // Consider this debug, only show when verbose
throws: false, // Should this log type throw an Error?
stamp: true, // Also prefix log output with a timestamp
prefix: 'Test', // Prefix string to show before each log msg
color: 'blue' // Color of output text (FG only)
}
}
})
Object.keys(myCli.settings.logging).forEach(type => {
myCli[type](`This is a(n) ${type} message!`)
myCli[type](`Called using: myCli.${type}('message')`)
})
additionalOptions.forEach(option => {
const name = option.name
const value = myCli.options[name]
myCli.log(`Option '${name}' = '${value}'`)
})
const username = myCli.prompt('Username: ')
if (myCli.confirm(`Allow user: '${username}' to process file: ${myCli.options.src}?`)) {
myCli.success(`File: ${myCli.options.src} processed by user: '${username}'`)
} else {
myCli.warn(`User: '${username}' not allowed to process file: ${myCli.options.src}`)
}