Skip to content

Commit 0284e38

Browse files
committed
Don't parse values for StopOptions.
This fixes bug #77.
1 parent f6420bc commit 0284e38

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

amtl/experimental/am-argparser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ Parser::parse_impl(const Vector<const char*>& args)
531531
if (i == args.length() - 1) {
532532
if (!option->canOmitValue())
533533
return option_needs_value(option);
534-
} else {
534+
} else if (!option->isToggle()) {
535535
value_ptr = args[++i];
536536
took_next_arg = true;
537537
}

tests/test-argparser.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ class TestArgparser : public Test
264264
return true;
265265
}
266266

267-
bool testStopArg() {
267+
bool testStopArg1() {
268268
Parser parser("help");
269269

270270
StopOption show_version(parser,
@@ -285,6 +285,28 @@ class TestArgparser : public Test
285285
return true;
286286
}
287287

288+
bool testStopArg2() {
289+
Parser parser("help");
290+
291+
BoolOption disable_watchdog(parser,
292+
"w", "disable-watchdog",
293+
Some(false),
294+
"Disable the watchdog timer.");
295+
StopOption show_version(parser,
296+
"-v", "--version",
297+
Some(false),
298+
"Show the version and exit.");
299+
StringOption filename(parser,
300+
"file",
301+
"SMX file to execute.");
302+
303+
if (!check(parser.parsev("-v", "-w", nullptr), "parse should succeed"))
304+
return false;
305+
if (!check(show_version.value() == true, "-v should be true"))
306+
return false;
307+
return true;
308+
}
309+
288310
bool Run() override
289311
{
290312
if (!testBasic())
@@ -299,7 +321,9 @@ class TestArgparser : public Test
299321
return false;
300322
if (!testRepeatArg())
301323
return false;
302-
if (!testStopArg())
324+
if (!testStopArg1())
325+
return false;
326+
if (!testStopArg2())
303327
return false;
304328
return true;
305329
};

0 commit comments

Comments
 (0)