Skip to content

Commit 42babf7

Browse files
committed
Refactor arg parser out of binary
1 parent 2e8ea16 commit 42babf7

File tree

2 files changed

+49
-48
lines changed

2 files changed

+49
-48
lines changed

bin/documentation.js

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -8,54 +8,9 @@ var documentation = require('../'),
88
path = require('path'),
99
fs = require('fs'),
1010
vfs = require('vinyl-fs'),
11-
12-
loadConfig = require('../lib/load_config.js');
13-
14-
var yargs = require('yargs')
15-
.usage('Usage: $0 <command> [options]')
16-
17-
.alias('f', 'format')
18-
.default('f', 'json')
19-
.describe('f', 'output format, of [json, md, html]')
20-
21-
.describe('lint', 'check output for common style and uniformity mistakes')
22-
23-
.describe('t', 'specify a theme: this must be a valid theme module')
24-
.alias('t', 'theme')
25-
26-
.boolean('p')
27-
.describe('p', 'generate documentation tagged as private')
28-
.alias('p', 'private')
29-
30-
.describe('name', 'project name. by default, inferred from package.json')
31-
.describe('version', 'project version. by default, inferred from package.json')
32-
33-
.boolean('shallow')
34-
.describe('shallow', 'shallow mode turns off dependency resolution, ' +
35-
'only processing the specified files (or the main script specified in package.json)')
36-
.default('shallow', false)
37-
38-
.boolean('polyglot')
39-
.describe('polyglot', 'polyglot mode turns off dependency resolution and ' +
40-
'enables multi-language support. use this to document c++')
41-
42-
.boolean('g')
43-
.describe('g', 'infer links to github in documentation')
44-
.alias('g', 'github')
45-
46-
.describe('o', 'output location. omit for stdout, otherwise is a filename ' +
47-
'for single-file outputs and a directory name for multi-file outputs like html')
48-
.alias('o', 'output')
49-
.default('o', 'stdout')
50-
51-
.describe('c', 'configuration file. an array defining explicit sort order')
52-
.alias('c', 'config')
53-
54-
.help('h')
55-
.alias('h', 'help')
56-
57-
.example('$0 foo.js', 'parse documentation in a given file'),
58-
argv = yargs.argv;
11+
loadConfig = require('../lib/load_config.js'),
12+
args = require('../lib/args.js'),
13+
argv = args.parse(process.argv.slice(2));
5914

6015
var inputs,
6116
name = argv.name,

lib/args.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
var args = require('yargs')
2+
.usage('Usage: $0 <command> [options]')
3+
4+
.alias('f', 'format')
5+
.default('f', 'json')
6+
.describe('f', 'output format, of [json, md, html]')
7+
8+
.describe('lint', 'check output for common style and uniformity mistakes')
9+
10+
.describe('t', 'specify a theme: this must be a valid theme module')
11+
.alias('t', 'theme')
12+
13+
.boolean('p')
14+
.describe('p', 'generate documentation tagged as private')
15+
.alias('p', 'private')
16+
17+
.describe('name', 'project name. by default, inferred from package.json')
18+
.describe('version', 'project version. by default, inferred from package.json')
19+
20+
.boolean('shallow')
21+
.describe('shallow', 'shallow mode turns off dependency resolution, ' +
22+
'only processing the specified files (or the main script specified in package.json)')
23+
.default('shallow', false)
24+
25+
.boolean('polyglot')
26+
.describe('polyglot', 'polyglot mode turns off dependency resolution and ' +
27+
'enables multi-language support. use this to document c++')
28+
29+
.boolean('g')
30+
.describe('g', 'infer links to github in documentation')
31+
.alias('g', 'github')
32+
33+
.describe('o', 'output location. omit for stdout, otherwise is a filename ' +
34+
'for single-file outputs and a directory name for multi-file outputs like html')
35+
.alias('o', 'output')
36+
.default('o', 'stdout')
37+
38+
.describe('c', 'configuration file. an array defining explicit sort order')
39+
.alias('c', 'config')
40+
41+
.help('h')
42+
.alias('h', 'help')
43+
44+
.example('$0 foo.js', 'parse documentation in a given file');
45+
46+
module.exports = args;

0 commit comments

Comments
 (0)