1
1
const commander = require ( 'commander' ) ;
2
2
const logger = require ( './logger' ) ;
3
-
3
+ const { commands } = require ( './cli-flags' ) ;
4
4
const { defaultCommands } = require ( './commands' ) ;
5
5
6
6
/**
@@ -12,38 +12,28 @@ const { defaultCommands } = require('./commands');
12
12
* @param {boolean } argsOnly false if all of process.argv has been provided, true if
13
13
* args is only a subset of process.argv that removes the first couple elements
14
14
*/
15
- function argParser ( options , args , argsOnly = false , name = '' , helpFunction = undefined , versionFunction = undefined , commands ) {
15
+ function argParser ( options , args , argsOnly = false , name = '' , helpFunction ) {
16
16
const parser = new commander . Command ( ) ;
17
17
// Set parser name
18
18
parser . name ( name ) ;
19
19
parser . storeOptionsAsProperties ( false ) ;
20
20
21
- if ( commands ) {
22
- commands . reduce ( ( parserInstance , cmd ) => {
23
- parser
24
- . command ( cmd . name )
25
- . alias ( cmd . alias )
26
- . description ( cmd . description )
27
- . usage ( cmd . usage )
28
- . allowUnknownOption ( true )
29
- . action ( async ( ) => {
30
- const cliArgs = args . slice ( args . indexOf ( cmd . name ) + 1 || args . indexOf ( cmd . alias ) + 1 ) ;
31
- return await require ( '../commands/ExternalCommand' ) . run ( defaultCommands [ cmd . name ] , ...cliArgs ) ;
32
- } ) ;
33
- return parser ;
34
- } , parser ) ;
35
-
36
- // Prevent default behavior
37
- parser . on ( 'command:*' , ( ) => { } ) ;
38
- }
21
+ commands . reduce ( ( parserInstance , cmd ) => {
22
+ parser
23
+ . command ( cmd . name )
24
+ . alias ( cmd . alias )
25
+ . description ( cmd . description )
26
+ . usage ( cmd . usage )
27
+ . allowUnknownOption ( true )
28
+ . action ( async ( ) => {
29
+ const cliArgs = args . slice ( args . indexOf ( cmd . name ) + 1 || args . indexOf ( cmd . alias ) + 1 ) ;
30
+ return await require ( '../commands/ExternalCommand' ) . run ( defaultCommands [ cmd . name ] , ...cliArgs ) ;
31
+ } ) ;
32
+ return parser ;
33
+ } , parser ) ;
39
34
40
- // Use customized version output if available
41
- if ( versionFunction ) {
42
- parser . on ( 'option:version' , ( ) => {
43
- versionFunction ( ) ;
44
- process . exit ( 0 ) ;
45
- } ) ;
46
- }
35
+ // Prevent default behavior
36
+ parser . on ( 'command:*' , ( ) => { } ) ;
47
37
48
38
// Use customized help output if available
49
39
if ( helpFunction ) {
0 commit comments