@@ -20,6 +20,26 @@ const isCommandUsed = commands =>
2020 return process . argv . includes ( cmd . name ) || process . argv . includes ( cmd . alias ) ;
2121 } ) ;
2222
23+ const resolveNegatedArgs = args => {
24+ args . _unknown . forEach ( arg => {
25+ if ( arg . includes ( '--' ) || arg . includes ( '--no' ) ) {
26+ const argPair = arg . split ( '=' ) ;
27+ const optName = arg . includes ( '--no' ) ? argPair [ 0 ] . slice ( 5 ) : argPair [ 0 ] . slice ( 2 ) ;
28+
29+ let argValue = arg . includes ( '--no' ) ? 'false' : argPair [ 1 ] ;
30+ if ( argValue === 'false' ) {
31+ argValue = false ;
32+ } else if ( argValue === 'true' ) {
33+ argValue = true ;
34+ }
35+
36+ const cliFlag = core . find ( opt => opt . name === optName ) ;
37+ args [ cliFlag . group ] [ optName ] = argValue ;
38+ args . _all [ optName ] = argValue ;
39+ }
40+ } ) ;
41+ }
42+
2343async function runCLI ( cli , commandIsUsed ) {
2444 let args ;
2545 const helpFlagExists = isFlagPresent ( process . argv , 'help' ) ;
@@ -40,6 +60,9 @@ async function runCLI(cli, commandIsUsed) {
4060 } else {
4161 try {
4262 args = cmdArgs ( core , { stopAtFirstUnknown : false , partial : true } ) ;
63+ if ( args . _unknown ) {
64+ resolveNegatedArgs ( args ) ;
65+ }
4366 const result = await cli . run ( args , core ) ;
4467 if ( ! result ) {
4568 return ;
@@ -68,7 +91,7 @@ async function runCLI(cli, commandIsUsed) {
6891 const newArgKeys = Object . keys ( argsMap ) . filter ( arg => ! keysToDelete . includes ( argsMap [ arg ] . pos ) ) ;
6992 process . argv = newArgKeys ;
7093 args = cmdArgs ( core , { stopAtFirstUnknown : false , partial : true } ) ;
71-
94+
7295 await cli . run ( args , core ) ;
7396 console . log ( '\n' )
7497 process . cliLogger . warn ( `duplicate flags found, defaulting to last set value` ) ;
0 commit comments