1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | 'use strict'
|
7 | const commandLineArgs = require('../')
|
8 | const fs = require('fs')
|
9 |
|
10 | const optionDefinitions = [
|
11 | { name: 'help', alias: 'h', type: Boolean },
|
12 | { name: 'files', type: String, multiple: true, defaultOption: true },
|
13 | { name: 'log-level', type: String }
|
14 | ]
|
15 |
|
16 | const options = commandLineArgs(optionDefinitions)
|
17 |
|
18 | const valid =
|
19 | options.help ||
|
20 | (
|
21 |
|
22 | options.files &&
|
23 | options.files.length &&
|
24 | options.files.every(fs.existsSync) &&
|
25 | [ 'info', 'warn', 'error', undefined ].includes(options['log-level'])
|
26 | )
|
27 |
|
28 | console.log('Your options are', valid ? 'valid' : 'invalid')
|
29 | console.log(options)
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|