UNPKG

1.51 kBJavaScriptView Raw
1'use strict'
2const commandLineArgs = require('../')
3const commandLineUsage = require('command-line-usage')
4
5/*
6 This example shows typical use alongside command-line-usage
7 https://github.com/75lb/command-line-usage
8*/
9
10const optionDefinitions = [
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 }
36]
37
38const options = commandLineArgs(optionDefinitions)
39
40if (options.help) {
41 const usage = commandLineUsage([
42 {
43 header: 'Typical Example',
44 content: 'A simple example demonstrating typical usage.'
45 },
46 {
47 header: 'Options',
48 optionList: optionDefinitions
49 },
50 {
51 content: 'Project home: [underline]{https://github.com/me/example}'
52 }
53 ])
54 console.log(usage)
55}
56
57/*
58
59Example output:
60
61$ node example/typical.js --help
62
63Typical Example
64
65 A simple example demonstrating typical usage.
66
67Options
68
69 -h, --help Display this usage guide.
70 --src <files> The input files to process
71 -t, --timeout <ms> Timeout value in ms
72 -l, --log info, warn or error
73
74 Project home: https://github.com/me/example
75
76*/