Skip to content

Commit 93243ca

Browse files
committed
Allow flag values to have attached bool values
1 parent 0d64c6e commit 93243ca

1 file changed

Lines changed: 15 additions & 21 deletions

File tree

libs/dimcli/cli.cpp

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ struct Cli::OptIndex {
286286
//-----------------------------------------------------------------------
287287
// Parsing
288288
// Will completely rebuild index for new command if one is found.
289-
bool parseToPlanValues(
289+
bool planValues(
290290
vector<PlanValue> * out,
291291
const vector<Cli::Arg> & args,
292292
Cli & cli
@@ -315,13 +315,13 @@ struct Cli::OptIndex {
315315
int pos
316316
);
317317

318-
bool parseOperandValue(
318+
bool planOperandValue(
319319
vector<PlanValue> * out,
320320
ParseState & st,
321321
Cli & cli,
322322
const vector<Cli::Arg> & args
323323
);
324-
bool parseOptionValue(
324+
bool planOptionValue(
325325
vector<PlanValue> * out,
326326
ParseState & st,
327327
Cli & cli,
@@ -2196,7 +2196,7 @@ static bool matchOperands(
21962196
}
21972197

21982198
//===========================================================================
2199-
bool Cli::OptIndex::parseOperandValue(
2199+
bool Cli::OptIndex::planOperandValue(
22002200
vector<PlanValue> * out,
22012201
ParseState & st,
22022202
Cli & cli,
@@ -2297,7 +2297,7 @@ static void addOptionMatch(
22972297
}
22982298

22992299
//===========================================================================
2300-
bool Cli::OptIndex::parseOptionValue(
2300+
bool Cli::OptIndex::planOptionValue(
23012301
vector<PlanValue> * out,
23022302
ParseState & st,
23032303
Cli & cli,
@@ -2356,7 +2356,7 @@ static bool commandRequired(const Cli::Config & cfg) {
23562356
}
23572357

23582358
//===========================================================================
2359-
bool Cli::OptIndex::parseToPlanValues(
2359+
bool Cli::OptIndex::planValues(
23602360
vector<PlanValue> * out,
23612361
const vector<Cli::Arg> & args,
23622362
Cli & cli
@@ -2398,7 +2398,7 @@ bool Cli::OptIndex::parseToPlanValues(
23982398
st.ptr = nullptr;
23992399
// Since that value consumes the rest of the argument,
24002400
// process it and then advance to next argument.
2401-
if (!parseOptionValue(out, st, cli, args))
2401+
if (!planOptionValue(out, st, cli, args))
24022402
return false;
24032403
goto NEXT_ARG;
24042404
}
@@ -2441,27 +2441,21 @@ bool Cli::OptIndex::parseToPlanValues(
24412441
if (st.optName.flags & fNameFinal)
24422442
st.moreOpts = false;
24432443

2444-
if (!st.optName.opt->m_bool) {
2444+
if (st.optName.opt->m_bool) {
2445+
// Found bool long name with value that is explicit or
2446+
// defaulted to "1", record and advance to the next argument.
2447+
addOptionMatch(out, st, st.ptr ? st.ptr : "1", args);
2448+
} else {
24452449
// Long option with (possibly empty) value, process it and
24462450
// advance to next argument.
2447-
if (!parseOptionValue(out, st, cli, args))
2451+
if (!planOptionValue(out, st, cli, args))
24482452
return false;
2449-
continue;
2450-
}
2451-
2452-
// Found bool long name.
2453-
if (st.ptr && st.optName.opt->m_flagValue) {
2454-
// Only regular bool opts support values.
2455-
cli.badUsage("Invalid '" + st.name + "' value", st.ptr);
2456-
return false;
24572453
}
2458-
// Record and advance to the next argument.
2459-
addOptionMatch(out, st, st.ptr ? st.ptr : "1", args);
24602454
continue;
24612455
}
24622456

24632457
// Positional value
2464-
if (!parseOperandValue(out, st, cli, args))
2458+
if (!planOperandValue(out, st, cli, args))
24652459
return false;
24662460
}
24672461

@@ -2591,7 +2585,7 @@ static bool parse(Cli & cli, vector<string> & rawArgs) {
25912585

25922586
// Extract raw values and match them to opts.
25932587
vector<PlanValue> planValues;
2594-
if (!ndx.parseToPlanValues(&planValues, args, cli))
2588+
if (!ndx.planValues(&planValues, args, cli))
25952589
return false;
25962590

25972591
// Parse values and copy them to defined opts.

0 commit comments

Comments
 (0)