11const commander = require ( 'commander' ) ;
22const logger = require ( './logger' ) ;
3-
3+ const { commands } = require ( './cli-flags' ) ;
44const { defaultCommands } = require ( './commands' ) ;
55
66/**
@@ -12,38 +12,28 @@ const { defaultCommands } = require('./commands');
1212 * @param {boolean } argsOnly false if all of process.argv has been provided, true if
1313 * args is only a subset of process.argv that removes the first couple elements
1414 */
15- function argParser ( options , args , argsOnly = false , name = '' , helpFunction = undefined , versionFunction = undefined , commands ) {
15+ function argParser ( options , args , argsOnly = false , name = '' , helpFunction ) {
1616 const parser = new commander . Command ( ) ;
1717 // Set parser name
1818 parser . name ( name ) ;
1919 parser . storeOptionsAsProperties ( false ) ;
2020
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 ) ;
3934
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:*' , ( ) => { } ) ;
4737
4838 // Use customized help output if available
4939 if ( helpFunction ) {
0 commit comments