[Option] Fix simple subcommand with positional arguments (#166859)
Fix subcommand detection when subcommand used with positional arguments. When there is only one valid subcommand passed, `ArgList::getSubCommand()` should return the correct subcommand even there are other positionals passed.
This commit is contained in:
parent
c9b4169997
commit
41825fbf0e
@ -230,10 +230,8 @@ StringRef ArgList::getSubCommand(
|
||||
HandleMultipleSubcommands(SubCommands);
|
||||
return {};
|
||||
}
|
||||
if (!OtherPositionals.empty()) {
|
||||
if (!OtherPositionals.empty())
|
||||
HandleOtherPositionals(OtherPositionals);
|
||||
return {};
|
||||
}
|
||||
|
||||
if (SubCommands.size() == 1)
|
||||
return SubCommands.front();
|
||||
|
||||
@ -192,6 +192,19 @@ TYPED_TEST(OptSubCommandTableTest, SubCommandParsing) {
|
||||
std::string::npos,
|
||||
ErrMsg.find("Option [lowercase] is not valid for SubCommand [bar]"));
|
||||
}
|
||||
|
||||
{
|
||||
// Test case 7: Check valid use of a valid subcommand following more
|
||||
// positional arguments.
|
||||
const char *Args[] = {"bar", "input"};
|
||||
InputArgList AL = T.ParseArgs(Args, MAI, MAC);
|
||||
StringRef SC = AL.getSubCommand(
|
||||
T.getSubCommands(), HandleMultipleSubcommands, HandleOtherPositionals);
|
||||
EXPECT_EQ(SC, "bar"); // valid subcommand
|
||||
EXPECT_NE(std::string::npos,
|
||||
ErrMsg.find("Unregistered positionals passed"));
|
||||
EXPECT_NE(std::string::npos, ErrMsg.find("input"));
|
||||
}
|
||||
}
|
||||
|
||||
TYPED_TEST(OptSubCommandTableTest, SubCommandHelp) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user