Skip to content

Commit 769b447

Browse files
committed
update examples
1 parent c7a43d9 commit 769b447

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

example/type.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,4 @@ $ node example/type.js package.json nothing.js
3232
{ file:
3333
[ FileDetails { filename: 'package.json', exists: true },
3434
FileDetails { filename: 'nothing.js', exists: false } ] }
35-
*/
36-
35+
*/

example/typical.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,31 @@ const commandLineUsage = require('command-line-usage')
88
*/
99

1010
const optionDefinitions = [
11-
{ name: 'help', alias: 'h', type: Boolean, description: 'Display this usage guide.' },
12-
{ name: 'src', type: String, multiple: true, defaultOption: true, description: 'The input files to process', typeLabel: '<files>' },
13-
{ name: 'timeout', alias: 't', type: Number, description: 'Timeout value in ms', typeLabel: '<ms>' },
14-
{ name: 'log', alias: 'l', type: Boolean, description: 'info, warn or error' }
11+
{
12+
name: 'help',
13+
alias: 'h',
14+
type: Boolean,
15+
description: 'Display this usage guide.'
16+
},
17+
{
18+
name: 'src',
19+
type: String,
20+
multiple: true,
21+
defaultOption: true,
22+
description: 'The input files to process',
23+
typeLabel: '<files>' },
24+
{
25+
name: 'timeout',
26+
alias: 't',
27+
type: Number,
28+
description: 'Timeout value in ms',
29+
typeLabel: '<ms>' },
30+
{
31+
name: 'log',
32+
alias: 'l',
33+
type: Boolean,
34+
description: 'info, warn or error'
35+
}
1536
]
1637

1738
const options = commandLineArgs(optionDefinitions)
@@ -33,8 +54,6 @@ if (options.help) {
3354
console.log(usage)
3455
}
3556

36-
console.log(options)
37-
3857
/*
3958
4059
Example output:
@@ -54,5 +73,4 @@ Options
5473
5574
Project home: https://github.com/me/example
5675
57-
{ help: true }
5876
*/

example/validate.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,13 @@ const valid =
2525
[ 'info', 'warn', 'error', undefined ].includes(options['log-level'])
2626
)
2727

28-
console.log('your options are', valid ? 'valid' : 'invalid', options)
28+
console.log('Your options are', valid ? 'valid' : 'invalid')
29+
console.log(options)
30+
31+
/*
32+
Example output:
33+
34+
$ node example/validate.js package.json README.md
35+
Your options are valid
36+
{ files: [ 'package.json', 'README.md' ] }
37+
*/

0 commit comments

Comments
 (0)