diff options
14 files changed, 54 insertions, 2 deletions
diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index 88ba0116ca..ad648186bd 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -532,11 +532,22 @@ int do_build(int ac, char const* const* av) for (; i < inputArgs.size() && !nativeOptionsPassed; ++i) { std::string const& arg = inputArgs[i]; + bool matched = false; + bool parsed = false; for (auto const& m : arguments) { - if (m.matches(arg) && m.parse(arg, i, inputArgs)) { + matched = m.matches(arg); + if (matched) { + parsed = m.parse(arg, i, inputArgs); break; } } + if (!(matched && parsed)) { + dir.clear(); + if (!matched) { + std::cerr << "Unknown argument " << arg << std::endl; + } + break; + } } if (nativeOptionsPassed) { @@ -806,11 +817,22 @@ int do_install(int ac, char const* const* av) for (decltype(inputArgs.size()) i = 0; i < inputArgs.size(); ++i) { std::string const& arg = inputArgs[i]; + bool matched = false; + bool parsed = false; for (auto const& m : arguments) { - if (m.matches(arg) && m.parse(arg, i, inputArgs)) { + matched = m.matches(arg); + if (matched) { + parsed = m.parse(arg, i, inputArgs); break; } } + if (!(matched && parsed)) { + dir.clear(); + if (!matched) { + std::cerr << "Unknown argument " << arg << std::endl; + } + break; + } } } diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake index 8072a2cad4..caf3c88966 100644 --- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake +++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake @@ -54,6 +54,14 @@ run_cmake_command(build-no-dir ${CMAKE_COMMAND} --build) run_cmake_command(build-no-cache ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR}) +run_cmake_command(build-unknown-command-short + ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR} -invalid-command) +run_cmake_command(build-unknown-command-long + ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR} --invalid-command) +run_cmake_command(build-unknown-command-partial-match + ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR} --targetinvalid) +run_cmake_command(build-invalid-target-syntax + ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR} --target=invalid) run_cmake_command(build-no-generator ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR}/cache-no-generator) run_cmake_command(build-bad-dir @@ -65,6 +73,10 @@ run_cmake_command(install-no-dir ${CMAKE_COMMAND} --install) run_cmake_command(install-bad-dir ${CMAKE_COMMAND} --install dir-does-not-exist) +run_cmake_command(install-unknown-command-short + ${CMAKE_COMMAND} --install ${RunCMake_SOURCE_DIR} -invalid-command) +run_cmake_command(install-unknown-command-long + ${CMAKE_COMMAND} --install ${RunCMake_SOURCE_DIR} --invalid-command) run_cmake_command(install-options-to-vars ${CMAKE_COMMAND} --install ${RunCMake_SOURCE_DIR}/dir-install-options-to-vars --strip --prefix /var/test --config sample --component pack) diff --git a/Tests/RunCMake/CommandLine/build-invalid-target-syntax-result.txt b/Tests/RunCMake/CommandLine/build-invalid-target-syntax-result.txt new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/Tests/RunCMake/CommandLine/build-invalid-target-syntax-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/build-invalid-target-syntax-stderr.txt b/Tests/RunCMake/CommandLine/build-invalid-target-syntax-stderr.txt new file mode 100644 index 0000000000..ce1c92d517 --- /dev/null +++ b/Tests/RunCMake/CommandLine/build-invalid-target-syntax-stderr.txt @@ -0,0 +1,2 @@ +^CMake Error: Invalid syntax used with --target +Usage: cmake --build \[<dir> \| --preset <preset>\] \[options\] \[-- \[native-options\]\] diff --git a/Tests/RunCMake/CommandLine/build-unknown-command-long-result.txt b/Tests/RunCMake/CommandLine/build-unknown-command-long-result.txt new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/Tests/RunCMake/CommandLine/build-unknown-command-long-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/build-unknown-command-long-stderr.txt b/Tests/RunCMake/CommandLine/build-unknown-command-long-stderr.txt new file mode 100644 index 0000000000..c8f1a03cb8 --- /dev/null +++ b/Tests/RunCMake/CommandLine/build-unknown-command-long-stderr.txt @@ -0,0 +1,2 @@ +^Unknown argument --invalid-command +Usage: cmake --build \[<dir> \| --preset <preset>\] \[options\] \[-- \[native-options\]\] diff --git a/Tests/RunCMake/CommandLine/build-unknown-command-partial-match-result.txt b/Tests/RunCMake/CommandLine/build-unknown-command-partial-match-result.txt new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/Tests/RunCMake/CommandLine/build-unknown-command-partial-match-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/build-unknown-command-partial-match-stderr.txt b/Tests/RunCMake/CommandLine/build-unknown-command-partial-match-stderr.txt new file mode 100644 index 0000000000..ce1c92d517 --- /dev/null +++ b/Tests/RunCMake/CommandLine/build-unknown-command-partial-match-stderr.txt @@ -0,0 +1,2 @@ +^CMake Error: Invalid syntax used with --target +Usage: cmake --build \[<dir> \| --preset <preset>\] \[options\] \[-- \[native-options\]\] diff --git a/Tests/RunCMake/CommandLine/build-unknown-command-short-result.txt b/Tests/RunCMake/CommandLine/build-unknown-command-short-result.txt new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/Tests/RunCMake/CommandLine/build-unknown-command-short-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/build-unknown-command-short-stderr.txt b/Tests/RunCMake/CommandLine/build-unknown-command-short-stderr.txt new file mode 100644 index 0000000000..a6cfeceace --- /dev/null +++ b/Tests/RunCMake/CommandLine/build-unknown-command-short-stderr.txt @@ -0,0 +1,2 @@ +^Unknown argument -invalid-command +Usage: cmake --build \[<dir> \| --preset <preset>\] \[options\] \[-- \[native-options\]\] diff --git a/Tests/RunCMake/CommandLine/install-unknown-command-long-result.txt b/Tests/RunCMake/CommandLine/install-unknown-command-long-result.txt new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/Tests/RunCMake/CommandLine/install-unknown-command-long-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/install-unknown-command-long-stderr.txt b/Tests/RunCMake/CommandLine/install-unknown-command-long-stderr.txt new file mode 100644 index 0000000000..e6cee6b45a --- /dev/null +++ b/Tests/RunCMake/CommandLine/install-unknown-command-long-stderr.txt @@ -0,0 +1,2 @@ +^Unknown argument --invalid-command +Usage: cmake --install <dir> \[options\] diff --git a/Tests/RunCMake/CommandLine/install-unknown-command-short-result.txt b/Tests/RunCMake/CommandLine/install-unknown-command-short-result.txt new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/Tests/RunCMake/CommandLine/install-unknown-command-short-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/install-unknown-command-short-stderr.txt b/Tests/RunCMake/CommandLine/install-unknown-command-short-stderr.txt new file mode 100644 index 0000000000..f690ec4304 --- /dev/null +++ b/Tests/RunCMake/CommandLine/install-unknown-command-short-stderr.txt @@ -0,0 +1,2 @@ +^Unknown argument -invalid-command +Usage: cmake --install <dir> \[options\] |