1- const _ = require ( " lodash" ) ;
2- const { root_command, skip_command } = require ( " ./constants" ) ;
3- const { parseArgs } = require ( " ./parse-args" ) ;
4- const didYouMean = require ( " didyoumean" ) ;
1+ const _ = require ( ' lodash' ) ;
2+ const { root_command, skip_command } = require ( ' ./constants' ) ;
3+ const { parseArgs } = require ( ' ./parse-args' ) ;
4+ const didYouMean = require ( ' didyoumean' ) ;
55
66didYouMean . threshold = 0.5 ;
77
8+ // eslint-disable-next-line no-unused-vars
89const execute = ( params , commands , instance ) => {
910 const args = parseArgs ( params . args , params . from ) ;
1011
@@ -17,7 +18,9 @@ const execute = (params, commands, instance) => {
1718 }
1819
1920 if ( ! usageOptions . length && command . name === root_command ) {
20- usageOptions . push ( command . options . find ( ( option ) => option . flags . name === "help" ) ) ;
21+ usageOptions . push (
22+ command . options . find ( ( option ) => option . flags . name === 'help' ) ,
23+ ) ;
2124 }
2225
2326 const operationOptions = usageOptions . filter ( ( option ) => option . operation ) ;
@@ -29,7 +32,7 @@ const execute = (params, commands, instance) => {
2932 } ) ;
3033 return ;
3134 } else {
32- let error = "" ;
35+ let error = '' ;
3336
3437 const processUserOptionData = ( userOption , option ) => {
3538 if ( userOption ) {
@@ -40,7 +43,7 @@ const execute = (params, commands, instance) => {
4043 if ( option . flags . value ) {
4144 if ( option . flags . value . variadic ) {
4245 return data . reduce ( ( acc , d ) => {
43- acc . push ( ...d . split ( "," ) . map ( option . flags . value . formatter ) ) ;
46+ acc . push ( ...d . split ( ',' ) . map ( option . flags . value . formatter ) ) ;
4447 return acc ;
4548 } , [ ] ) ;
4649 } else {
@@ -55,7 +58,9 @@ const execute = (params, commands, instance) => {
5558 const parsedOptionsObject = command . options . reduce ( ( acc , option ) => {
5659 if ( error ) return acc ;
5760
58- const userOption = usageOptions . find ( ( o ) => o . flags . name === option . flags . name ) ;
61+ const userOption = usageOptions . find (
62+ ( o ) => o . flags . name === option . flags . name ,
63+ ) ;
5964
6065 if ( ! userOption && option . required ) {
6166 error = `required option '${ option . flags . raw } ' not specified` ;
@@ -65,7 +70,9 @@ const execute = (params, commands, instance) => {
6570 const flagValue = processUserOptionData ( userOption , option ) ;
6671 if ( ! option . operation ) {
6772 const internal = option . internal || { } ;
68- acc [ internal . name || option . flags . name ] = internal . formatter ? internal . formatter ( flagValue ) : flagValue ;
73+ acc [ internal . name || option . flags . name ] = internal . formatter
74+ ? internal . formatter ( flagValue )
75+ : flagValue ;
6976 }
7077
7178 return acc ;
@@ -87,7 +94,7 @@ const processArgs = (commands, args) => {
8794 let command = null ;
8895 let usageOptions = [ ] ;
8996 let walkingOption = null ;
90- let error = "" ;
97+ let error = '' ;
9198
9299 let allFlagKeys = [ ] ;
93100
@@ -97,33 +104,44 @@ const processArgs = (commands, args) => {
97104 if ( i === 0 ) {
98105 command = commands [ arg ] ;
99106
100- if ( ! command && ! arg . startsWith ( "-" ) ) {
107+ if ( ! command && ! arg . startsWith ( '-' ) ) {
101108 const tip = didYouMean ( arg , _ . keys ( commands ) ) ;
102- error = `unknown command ${ arg } ${ tip ? `\n(Did you mean ${ tip } ?)` : "" } ` ;
109+ error = `unknown command ${ arg } ${
110+ tip ? `\n(Did you mean ${ tip } ?)` : ''
111+ } `;
103112 } else if ( ! command ) {
104113 command = commands [ root_command ] ;
105114 }
106115
107116 if ( command ) {
108- allFlagKeys = command . options . reduce ( ( acc , option ) => [ ...acc , ...option . flags . keys ] , [ ] ) ;
117+ allFlagKeys = command . options . reduce (
118+ ( acc , option ) => [ ...acc , ...option . flags . keys ] ,
119+ [ ] ,
120+ ) ;
109121 }
110122 }
111123
112124 if ( error ) return ;
113125
114- if ( arg . startsWith ( "-" ) ) {
115- const option = command . options . find ( ( option ) => option . flags . keys . includes ( arg ) ) ;
126+ if ( arg . startsWith ( '-' ) ) {
127+ const option = command . options . find ( ( option ) =>
128+ option . flags . keys . includes ( arg ) ,
129+ ) ;
116130
117131 if ( ! option ) {
118132 const tip = didYouMean ( arg , allFlagKeys ) ;
119- error = `unknown option ${ arg } ${ tip ? `\n(Did you mean ${ tip } ?)` : "" } ` ;
133+ error = `unknown option ${ arg } ${
134+ tip ? `\n(Did you mean ${ tip } ?)` : ''
135+ } `;
120136 }
121137
122138 if ( option ) {
123139 if ( walkingOption && walkingOption . flags . name === option . flags . name ) {
124140 return ;
125141 }
126- const existedOption = usageOptions . find ( ( o ) => o . flags . name === option . flags . name ) ;
142+ const existedOption = usageOptions . find (
143+ ( o ) => o . flags . name === option . flags . name ,
144+ ) ;
127145 if ( existedOption ) {
128146 walkingOption = existedOption ;
129147 } else {
0 commit comments