@@ -13,57 +13,15 @@ var parsedArgs = parseArgs();
1313commands [ parsedArgs . command ] ( documentation , parsedArgs ) ;
1414
1515function parseArgs ( ) {
16- // reset() needs to be called at parse time because the yargs module uses an
17- // internal global variable to hold option state
18- var argv = addCommands ( yargs , true )
19- . usage ( 'Usage: $0 <command> [options]' )
16+
17+ var commandArgv = addCommands ( yargs )
2018 . version ( function ( ) {
2119 return require ( '../package' ) . version ;
2220 } )
23- . option ( 'shallow' , {
24- describe : 'shallow mode turns off dependency resolution, ' +
25- 'only processing the specified files (or the main script specified in package.json)' ,
26- default : false ,
27- type : 'boolean'
28- } )
29- . option ( 'config' , {
30- describe : 'configuration file. an array defining explicit sort order' ,
31- alias : 'c'
32- } )
33- . option ( 'external' , {
34- describe : 'a string / glob match pattern that defines which external ' +
35- 'modules will be whitelisted and included in the generated documentation.' ,
36- default : null
37- } )
38- . option ( 'extension' , {
39- describe : 'only input source files matching this extension will be parsed, ' +
40- 'this option can be used multiple times.' ,
41- alias : 'e'
42- } )
43- . option ( 'polyglot' , {
44- type : 'boolean' ,
45- describe : 'polyglot mode turns off dependency resolution and ' +
46- 'enables multi-language support. use this to document c++'
47- } )
48- . option ( 'private' , {
49- describe : 'generate documentation tagged as private' ,
50- type : 'boolean' ,
51- default : false ,
52- alias : 'p'
53- } )
54- . option ( 'access' , {
55- describe : 'Include only comments with a given access level, out of private, ' +
56- 'protected, public, undefined. By default, public, protected, and undefined access ' +
57- 'levels are included' ,
58- choices : [ 'public' , 'private' , 'protected' , 'undefined' ] ,
59- alias : 'a'
60- } )
61- . option ( 'github' , {
62- type : 'boolean' ,
63- describe : 'infer links to github in documentation' ,
64- alias : 'g'
65- } )
66- . argv ;
21+ . argv ;
22+
23+ var argv = commands [ commandArgv . _ [ 0 ] ]
24+ . parseArgs ( yargs . reset ( ) ) . argv ;
6725
6826 var options = { } ;
6927 if ( argv . config ) {
@@ -109,14 +67,8 @@ function parseArgs() {
10967}
11068
11169function addCommands ( parser , descriptionOnly ) {
112- parser = parser . demand ( 1 ) ;
113- for ( var cmd in commands ) {
114- if ( descriptionOnly ) {
115- parser = parser . command ( cmd , commands [ cmd ] . description ) ;
116- } else {
117- parser = parser . command ( cmd , commands [ cmd ] . description , commands [ cmd ] . parseArgs ) ;
118- }
119- }
120- return parser . help ( 'help' ) ;
70+ return Object . keys ( commands ) . reduce ( function ( parser , cmd ) {
71+ return parser . command ( cmd , commands [ cmd ] . description ) ;
72+ } , parser . demand ( 1 ) ) . help ( 'help' ) ;
12173}
12274
0 commit comments