diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2023-02-15 18:03:18 +0100 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2023-02-15 19:00:34 +0100 |
commit | d79f0df1227f348e6f7443355d86e9b0ef801107 (patch) | |
tree | f4082776ae64bba6845c9a5668b326e28997b7d8 /src | |
parent | d57a7bf8964de96456bd0f9a886c9f2cfa326e60 (diff) | |
download | justbuild-d79f0df1227f348e6f7443355d86e9b0ef801107.tar.gz |
CLI: enforce maximal number of positional arguments
..., i.e., the requirement that the positional arguments form a
syntactically valid target name. An explicit error message (created
by the target-name parsing) is preferrable over tacitly dropping all
but the last up to two arguments (which is the meaning of CLI11's
expected(2)).
While there, drop duplicate full stop in error message.
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/common/cli.hpp | 24 | ||||
-rw-r--r-- | src/buildtool/main/main.cpp | 2 |
2 files changed, 12 insertions, 14 deletions
diff --git a/src/buildtool/common/cli.hpp b/src/buildtool/common/cli.hpp index c638193b..46e8a7c9 100644 --- a/src/buildtool/common/cli.hpp +++ b/src/buildtool/common/cli.hpp @@ -228,19 +228,17 @@ static inline auto SetupAnalysisArguments( "Instead of the target result, request input for this action.") ->type_name("ACTION"); app->add_option_function<std::vector<std::string>>( - "target", - [clargs](auto const& target_raw) { - if (target_raw.size() > 1) { - clargs->target = - nlohmann::json{target_raw[0], target_raw[1]}; - } - else { - clargs->target = nlohmann::json{target_raw[0]}[0]; - } - }, - "Module and target name to build.\n" - "Assumes current module if module name is omitted.") - ->expected(2); + "target", + [clargs](auto const& target_raw) { + if (target_raw.size() == 1) { + clargs->target = nlohmann::json(target_raw[0]); + } + else { + clargs->target = nlohmann::json(target_raw); + } + }, + "Module and target name to build.\n" + "Assumes current module if module name is omitted."); app->add_option("--target-root", clargs->target_root, "Path of the target files' root directory.\n" diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp index 146ec221..3ffb8159 100644 --- a/src/buildtool/main/main.cpp +++ b/src/buildtool/main/main.cpp @@ -550,7 +550,7 @@ void SetupHashFunction() { Base::EntityName{Base::NamedTarget{main_repo, current_module, ""}}, [&clargs](std::string const& parse_err) { Logger::Log(LogLevel::Error, - "Parsing target name {} failed with:\n{}.", + "Parsing target name {} failed with:\n{}", clargs.target->dump(), parse_err); }); |