cmArgumentParser: enhance multi command management

This commit is contained in:
Marc Chevrier
2026-09-14 18:24:48 +02:00
parent a53691b73a
commit b53f05cd8c
7 changed files with 31 additions and 11 deletions
+14 -1
View File
@@ -127,7 +127,8 @@ void Instance::Bind(NonEmpty<std::vector<std::string>>& val)
ExpectAtLeast{ 1 });
}
void Instance::Bind(std::vector<std::vector<std::string>>& multiVal)
void Instance::Bind(
MaybeEmpty<std::vector<std::vector<std::string>>>& multiVal)
{
multiVal.emplace_back();
std::vector<std::string>& val = multiVal.back();
@@ -139,6 +140,18 @@ void Instance::Bind(std::vector<std::vector<std::string>>& multiVal)
ExpectAtLeast{ 0 });
}
void Instance::Bind(NonEmpty<std::vector<std::vector<std::string>>>& multiVal)
{
multiVal.emplace_back();
std::vector<std::string>& val = multiVal.back();
this->Bind(
[&val](cm::string_view arg) -> Continue {
val.emplace_back(arg);
return Continue::Yes;
},
ExpectAtLeast{ 1 });
}
void Instance::Consume(cm::string_view arg)
{
ParserState& state = this->GetState();
+2 -1
View File
@@ -228,7 +228,8 @@ public:
void Bind(Maybe<std::string>& val);
void Bind(MaybeEmpty<std::vector<std::string>>& val);
void Bind(NonEmpty<std::vector<std::string>>& val);
void Bind(std::vector<std::vector<std::string>>& val);
void Bind(MaybeEmpty<std::vector<std::vector<std::string>>>& val);
void Bind(NonEmpty<std::vector<std::vector<std::string>>>& val);
template <typename U>
void Bind(NonEmpty<std::vector<std::pair<std::string, U>>>& val,
+1 -1
View File
@@ -79,7 +79,7 @@ bool cmExecuteProcessCommand(std::vector<std::string> const& args,
struct Arguments : public ArgumentParser::ParseResult
{
std::vector<std::vector<std::string>> Commands;
ArgumentParser::MaybeEmpty<std::vector<std::vector<std::string>>> Commands;
std::string OutputVariable;
std::string ErrorVariable;
std::string ResultVariable;
+4 -2
View File
@@ -487,8 +487,10 @@ static bool HandleSetupMode(std::vector<std::string> const& args,
{
ArgumentParser::NonEmpty<std::string> ExportSetName;
ArgumentParser::NonEmpty<std::string> CxxModulesDirectory;
std::vector<std::vector<std::string>> PackageDependencyArgs;
std::vector<std::vector<std::string>> TargetArgs;
ArgumentParser::MaybeEmpty<std::vector<std::vector<std::string>>>
PackageDependencyArgs;
ArgumentParser::MaybeEmpty<std::vector<std::vector<std::string>>>
TargetArgs;
};
auto parser = cmArgumentParser<SetupArguments>{};
+1 -1
View File
@@ -1016,7 +1016,7 @@ bool HandleTargetsMode(std::vector<std::string> const& args,
ArgumentParser::MaybeEmpty<std::vector<std::string>> PublicHeader;
ArgumentParser::MaybeEmpty<std::vector<std::string>> Resource;
ArgumentParser::MaybeEmpty<std::vector<std::string>> CxxModulesBmi;
std::vector<std::vector<std::string>> FileSets;
ArgumentParser::MaybeEmpty<std::vector<std::vector<std::string>>> FileSets;
};
static auto const argHelper =
+1 -1
View File
@@ -42,7 +42,7 @@ auto const FileSetArgsParser = cmArgumentParser<FileSetArgs>()
struct FileSetsArgs
{
std::vector<std::vector<std::string>> FileSets;
ArgumentParser::MaybeEmpty<std::vector<std::vector<std::string>>> FileSets;
};
auto const FileSetsArgsParser =
+8 -4
View File
@@ -45,10 +45,14 @@ struct Result : ArgumentParser::ParseResult
cm::optional<ArgumentParser::NonEmpty<std::vector<std::string>>> List5;
cm::optional<ArgumentParser::MaybeEmpty<std::vector<std::string>>> List6;
std::vector<std::vector<std::string>> Multi1;
std::vector<std::vector<std::string>> Multi2;
cm::optional<std::vector<std::vector<std::string>>> Multi3;
cm::optional<std::vector<std::vector<std::string>>> Multi4;
ArgumentParser::MaybeEmpty<std::vector<std::vector<std::string>>> Multi1;
ArgumentParser::MaybeEmpty<std::vector<std::vector<std::string>>> Multi2;
cm::optional<
ArgumentParser::MaybeEmpty<std::vector<std::vector<std::string>>>>
Multi3;
cm::optional<
ArgumentParser::MaybeEmpty<std::vector<std::vector<std::string>>>>
Multi4;
cm::optional<std::string> Pos0;
cm::optional<std::string> Pos1;