File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -268,6 +268,10 @@ inline std::string RequiresArgumentErr(const std::string& arg) {
268268 return arg + " requires an argument" ;
269269}
270270
271+ inline std::string UnexpectedArgumentErr (const std::string& arg) {
272+ return arg + " does not take an argument" ;
273+ }
274+
271275inline std::string NegationImpliesBooleanError (const std::string& arg) {
272276 return arg + " is an invalid negation because it is not a boolean option" ;
273277}
@@ -475,6 +479,10 @@ void OptionsParser<Options>::Parse(
475479 value = value.substr (1 ); // Treat \- as escaping an -.
476480 }
477481 }
482+ } else if (info.type == kBoolean && equals_index != std::string::npos) {
483+ // Boolean options don't accept arguments
484+ errors->push_back (UnexpectedArgumentErr (name));
485+ break ;
478486 }
479487
480488 switch (info.type ) {
Original file line number Diff line number Diff line change @@ -17,6 +17,8 @@ requiresArgument('--eval');
1717missingOption ( '--allow-fs-read=*' , '--permission' ) ;
1818missingOption ( '--allow-fs-write=*' , '--permission' ) ;
1919
20+ forbidsArgument ( '--check' ) ;
21+
2022function missingOption ( option , requiredOption ) {
2123 const r = spawnSync ( process . execPath , [ option ] , { encoding : 'utf8' } ) ;
2224 assert . strictEqual ( r . status , 1 ) ;
@@ -36,3 +38,15 @@ function requiresArgument(option) {
3638 `${ process . execPath } : ${ option } requires an argument`
3739 ) ;
3840}
41+
42+ function forbidsArgument ( option ) {
43+ const r = spawnSync ( process . execPath , [ `${ option } =invalid` ] , { encoding : 'utf8' } ) ;
44+
45+ assert . strictEqual ( r . status , 9 ) ;
46+
47+ const msg = r . stderr . split ( / \r ? \n / ) [ 0 ] ;
48+ assert . strictEqual (
49+ msg ,
50+ `${ process . execPath } : ${ option } does not take an argument`
51+ ) ;
52+ }
You can’t perform that action at this time.
0 commit comments