From ac98ebe76737eb6c20c572771b5ebb220cb0a428 Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Fri, 20 May 2022 21:40:06 -0400 Subject: [PATCH 01/13] add tab completion Signed-off-by: Mabel Zhang --- CMakeLists.txt | 1 + src/cmd/CMakeLists.txt | 16 ++++++++ src/cmd/gazebo.bash_completion.sh | 49 +++++++++++++++++++++++ src/ign_TEST.cc | 66 +++++++++++++++++++++++++++++++ 4 files changed, 132 insertions(+) create mode 100644 src/cmd/gazebo.bash_completion.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 550e666c33..548f63e71e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -136,6 +136,7 @@ set(IGN_MATH_VER ${ignition-math6_VERSION_MAJOR}) ign_find_package(ignition-tools REQUIRED PKGCONFIG "ignition-tools") +set(IGN_TOOLS_VER 1) #-------------------------------------- # Find protobuf diff --git a/src/cmd/CMakeLists.txt b/src/cmd/CMakeLists.txt index a1ff8091c4..0d6a2966a1 100644 --- a/src/cmd/CMakeLists.txt +++ b/src/cmd/CMakeLists.txt @@ -117,3 +117,19 @@ set(ign_model_ruby_path "${cmd_model_script_generated_test}") configure_file( "model.yaml.in" "${CMAKE_BINARY_DIR}/test/conf/model${PROJECT_VERSION_MAJOR}.yaml" @ONLY) + + +#=============================================================================== +# Bash completion + +# Tack version onto and install the bash completion script +configure_file( + "gazebo.bash_completion.sh" + "${CMAKE_CURRENT_BINARY_DIR}/gazebo${PROJECT_VERSION_MAJOR}.bash_completion.sh" @ONLY) +if (HAVE_IGN_TOOLS) + install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/gazebo${PROJECT_VERSION_MAJOR}.bash_completion.sh + DESTINATION + ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}/gz/gz${IGN_TOOLS_VER}.completion.d) +endif() diff --git a/src/cmd/gazebo.bash_completion.sh b/src/cmd/gazebo.bash_completion.sh new file mode 100644 index 0000000000..59d9892460 --- /dev/null +++ b/src/cmd/gazebo.bash_completion.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +# bash tab-completion + +# This is a per-library function definition, used in conjunction with the +# top-level entry point in ign-tools. + +# NOTE: In Garden+, replace `gazebo` in function name to align with subcommand, +# for ign-tools/etc/ign.bash_completion.sh to find this function. +function _gz_gazebo +{ + if [[ ${COMP_WORDS[COMP_CWORD]} == -* ]]; then + # Specify options (-*) word list for this subcommand + COMPREPLY=($(compgen -W " + -g + --iterations + --levels + --network-role + --network-secondaries + --record + --record-path + --record-resources + --record-topic + --log-overwrite + --log-compress + --playback + -r + -s + -v --verbose + --gui-config + --physics-engine + --render-engine + --render-engine-gui + --render-engine-server + --version + -z + -h --help + --force-version + --versions + " -- "${COMP_WORDS[COMP_CWORD]}" )) + return + else + # Just use bash default auto-complete, because we never have two + # subcommands in the same line. If that is ever needed, change here to + # detect subsequent subcommands + COMPREPLY=($(compgen -o default -- "${COMP_WORDS[COMP_CWORD]}")) + return + fi +} diff --git a/src/ign_TEST.cc b/src/ign_TEST.cc index a1d7e71871..184de5edbd 100644 --- a/src/ign_TEST.cc +++ b/src/ign_TEST.cc @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -160,3 +161,68 @@ TEST(CmdLine, ResourcePath) EXPECT_EQ(output.find("Unable to find file plugins.sdf"), std::string::npos) << output; } + +////////////////////////////////////////////////// +/// \brief Check --help message and bash completion script for consistent flags +TEST(CmdLine, HelpVsCompletionFlags) +{ + // Flags in help message + std::string output = customExecStr(kIgnCommand + " gazebo --help"); + EXPECT_NE(std::string::npos, output.find("-g")) << output; + EXPECT_NE(std::string::npos, output.find("--iterations")) << output; + EXPECT_NE(std::string::npos, output.find("--levels")) << output; + EXPECT_NE(std::string::npos, output.find("--network-role")) << output; + EXPECT_NE(std::string::npos, output.find("--network-secondaries")) << output; + EXPECT_NE(std::string::npos, output.find("--record")) << output; + EXPECT_NE(std::string::npos, output.find("--record-path")) << output; + EXPECT_NE(std::string::npos, output.find("--record-resources")) << output; + EXPECT_NE(std::string::npos, output.find("--record-topic")) << output; + EXPECT_NE(std::string::npos, output.find("--log-overwrite")) << output; + EXPECT_NE(std::string::npos, output.find("--log-compress")) << output; + EXPECT_NE(std::string::npos, output.find("--playback")) << output; + EXPECT_NE(std::string::npos, output.find("-r")) << output; + EXPECT_NE(std::string::npos, output.find("-s")) << output; + EXPECT_NE(std::string::npos, output.find("--verbose")) << output; + EXPECT_NE(std::string::npos, output.find("--gui-config")) << output; + EXPECT_NE(std::string::npos, output.find("--physics-engine")) << output; + EXPECT_NE(std::string::npos, output.find("--render-engine")) << output; + EXPECT_NE(std::string::npos, output.find("--render-engine-gui")) << output; + EXPECT_NE(std::string::npos, output.find("--render-engine-server")) << output; + EXPECT_NE(std::string::npos, output.find("--version")) << output; + EXPECT_NE(std::string::npos, output.find("-z")) << output; + EXPECT_NE(std::string::npos, output.find("--help")) << output; + EXPECT_NE(std::string::npos, output.find("--force-version")) << output; + EXPECT_NE(std::string::npos, output.find("--versions")) << output; + + // Flags in bash completion + std::ifstream scriptFile(std::string(PROJECT_SOURCE_PATH) + + "/src/cmd/gazebo.bash_completion.sh"); + std::string script((std::istreambuf_iterator(scriptFile)), + std::istreambuf_iterator()); + + EXPECT_NE(std::string::npos, script.find("-g")) << script; + EXPECT_NE(std::string::npos, script.find("--iterations")) << script; + EXPECT_NE(std::string::npos, script.find("--levels")) << script; + EXPECT_NE(std::string::npos, script.find("--network-role")) << script; + EXPECT_NE(std::string::npos, script.find("--network-secondaries")) << script; + EXPECT_NE(std::string::npos, script.find("--record")) << script; + EXPECT_NE(std::string::npos, script.find("--record-path")) << script; + EXPECT_NE(std::string::npos, script.find("--record-resources")) << script; + EXPECT_NE(std::string::npos, script.find("--record-topic")) << script; + EXPECT_NE(std::string::npos, script.find("--log-overwrite")) << script; + EXPECT_NE(std::string::npos, script.find("--log-compress")) << script; + EXPECT_NE(std::string::npos, script.find("--playback")) << script; + EXPECT_NE(std::string::npos, script.find("-r")) << script; + EXPECT_NE(std::string::npos, script.find("-s")) << script; + EXPECT_NE(std::string::npos, script.find("--verbose")) << script; + EXPECT_NE(std::string::npos, script.find("--gui-config")) << script; + EXPECT_NE(std::string::npos, script.find("--physics-engine")) << script; + EXPECT_NE(std::string::npos, script.find("--render-engine")) << script; + EXPECT_NE(std::string::npos, script.find("--render-engine-gui")) << script; + EXPECT_NE(std::string::npos, script.find("--render-engine-server")) << script; + EXPECT_NE(std::string::npos, script.find("--version")) << script; + EXPECT_NE(std::string::npos, script.find("-z")) << script; + EXPECT_NE(std::string::npos, script.find("--help")) << script; + EXPECT_NE(std::string::npos, script.find("--force-version")) << script; + EXPECT_NE(std::string::npos, script.find("--versions")) << script; +} From 9c8f7fc7c26bb240460798d99623ce66dbf4877d Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Fri, 20 May 2022 23:10:07 -0400 Subject: [PATCH 02/13] fix install Signed-off-by: Mabel Zhang --- src/cmd/CMakeLists.txt | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/cmd/CMakeLists.txt b/src/cmd/CMakeLists.txt index 0d6a2966a1..ca6a9de28c 100644 --- a/src/cmd/CMakeLists.txt +++ b/src/cmd/CMakeLists.txt @@ -126,10 +126,8 @@ configure_file( configure_file( "gazebo.bash_completion.sh" "${CMAKE_CURRENT_BINARY_DIR}/gazebo${PROJECT_VERSION_MAJOR}.bash_completion.sh" @ONLY) -if (HAVE_IGN_TOOLS) - install( - FILES - ${CMAKE_CURRENT_BINARY_DIR}/gazebo${PROJECT_VERSION_MAJOR}.bash_completion.sh - DESTINATION - ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}/gz/gz${IGN_TOOLS_VER}.completion.d) -endif() +install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/gazebo${PROJECT_VERSION_MAJOR}.bash_completion.sh + DESTINATION + ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}/gz/gz${IGN_TOOLS_VER}.completion.d) From b8b8598e8a28b22c72336658e6334c47144016e1 Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Sat, 21 May 2022 00:44:05 -0400 Subject: [PATCH 03/13] change test name Signed-off-by: Mabel Zhang --- src/ign_TEST.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ign_TEST.cc b/src/ign_TEST.cc index 184de5edbd..dfa8162832 100644 --- a/src/ign_TEST.cc +++ b/src/ign_TEST.cc @@ -164,7 +164,7 @@ TEST(CmdLine, ResourcePath) ////////////////////////////////////////////////// /// \brief Check --help message and bash completion script for consistent flags -TEST(CmdLine, HelpVsCompletionFlags) +TEST(CmdLine, GazeboHelpVsCompletionFlags) { // Flags in help message std::string output = customExecStr(kIgnCommand + " gazebo --help"); From fd1a125f114d848a11d380757e52b202ba251698 Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Fri, 3 Jun 2022 00:42:47 -0400 Subject: [PATCH 04/13] PR comments Signed-off-by: Mabel Zhang --- src/cmd/gazebo.bash_completion.sh | 17 +++++++++++++++++ src/ign_TEST.cc | 6 ++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/cmd/gazebo.bash_completion.sh b/src/cmd/gazebo.bash_completion.sh index 59d9892460..622c64d25f 100644 --- a/src/cmd/gazebo.bash_completion.sh +++ b/src/cmd/gazebo.bash_completion.sh @@ -1,4 +1,19 @@ #!/usr/bin/env bash +# +# Copyright (C) 2022 Open Source Robotics Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# # bash tab-completion @@ -11,6 +26,8 @@ function _gz_gazebo { if [[ ${COMP_WORDS[COMP_CWORD]} == -* ]]; then # Specify options (-*) word list for this subcommand + # NOTE: In Fortress+, add --headless-rendering. + # Update ../ign_TEST.cc accordingly. COMPREPLY=($(compgen -W " -g --iterations diff --git a/src/ign_TEST.cc b/src/ign_TEST.cc index dfa8162832..313522474c 100644 --- a/src/ign_TEST.cc +++ b/src/ign_TEST.cc @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -195,8 +196,9 @@ TEST(CmdLine, GazeboHelpVsCompletionFlags) EXPECT_NE(std::string::npos, output.find("--versions")) << output; // Flags in bash completion - std::ifstream scriptFile(std::string(PROJECT_SOURCE_PATH) + - "/src/cmd/gazebo.bash_completion.sh"); + std::string scriptPath = common::joinPaths(std::string(PROJECT_SOURCE_PATH), + "src", "cmd", "gazebo.bash_completion.sh"); + std::ifstream scriptFile(scriptPath); std::string script((std::istreambuf_iterator(scriptFile)), std::istreambuf_iterator()); From 544e76bb3a5643072e51adaca5717914191b9009 Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Fri, 3 Jun 2022 18:16:27 -0400 Subject: [PATCH 05/13] fix namespace Signed-off-by: Mabel Zhang --- src/ign_TEST.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ign_TEST.cc b/src/ign_TEST.cc index 313522474c..abc5676f4d 100644 --- a/src/ign_TEST.cc +++ b/src/ign_TEST.cc @@ -196,7 +196,8 @@ TEST(CmdLine, GazeboHelpVsCompletionFlags) EXPECT_NE(std::string::npos, output.find("--versions")) << output; // Flags in bash completion - std::string scriptPath = common::joinPaths(std::string(PROJECT_SOURCE_PATH), + std::string scriptPath = ignition::common::joinPaths( + std::string(PROJECT_SOURCE_PATH), "src", "cmd", "gazebo.bash_completion.sh"); std::ifstream scriptFile(scriptPath); std::string script((std::istreambuf_iterator(scriptFile)), From b34bbe9ed7246c77706c10773427acd397d4c920 Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Fri, 3 Jun 2022 23:23:57 -0400 Subject: [PATCH 06/13] add bash completion for model command Signed-off-by: Mabel Zhang --- src/cmd/CMakeLists.txt | 9 +++++ src/cmd/gazebo.bash_completion.sh | 4 +-- src/cmd/model.bash_completion.sh | 57 +++++++++++++++++++++++++++++++ src/ign_TEST.cc | 34 ++++++++++++++++++ 4 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 src/cmd/model.bash_completion.sh diff --git a/src/cmd/CMakeLists.txt b/src/cmd/CMakeLists.txt index ca6a9de28c..b61fee1245 100644 --- a/src/cmd/CMakeLists.txt +++ b/src/cmd/CMakeLists.txt @@ -131,3 +131,12 @@ install( ${CMAKE_CURRENT_BINARY_DIR}/gazebo${PROJECT_VERSION_MAJOR}.bash_completion.sh DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}/gz/gz${IGN_TOOLS_VER}.completion.d) + +configure_file( + "model.bash_completion.sh" + "${CMAKE_CURRENT_BINARY_DIR}/model${PROJECT_VERSION_MAJOR}.bash_completion.sh" @ONLY) +install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/model${PROJECT_VERSION_MAJOR}.bash_completion.sh + DESTINATION + ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}/gz/gz${IGN_TOOLS_VER}.completion.d) diff --git a/src/cmd/gazebo.bash_completion.sh b/src/cmd/gazebo.bash_completion.sh index 622c64d25f..8608b057e4 100644 --- a/src/cmd/gazebo.bash_completion.sh +++ b/src/cmd/gazebo.bash_completion.sh @@ -20,8 +20,8 @@ # This is a per-library function definition, used in conjunction with the # top-level entry point in ign-tools. -# NOTE: In Garden+, replace `gazebo` in function name to align with subcommand, -# for ign-tools/etc/ign.bash_completion.sh to find this function. +# TODO(anyone): In Garden+, replace `gazebo` in function name to align with +# subcommand, for ign-tools/etc/ign.bash_completion.sh to find this function. function _gz_gazebo { if [[ ${COMP_WORDS[COMP_CWORD]} == -* ]]; then diff --git a/src/cmd/model.bash_completion.sh b/src/cmd/model.bash_completion.sh new file mode 100644 index 0000000000..b37c1ca394 --- /dev/null +++ b/src/cmd/model.bash_completion.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash +# +# Copyright (C) 2022 Open Source Robotics Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# bash tab-completion + +# This is a per-library function definition, used in conjunction with the +# top-level entry point in ign-tools. + +GZ_MODEL_WORDLIST=" + --list + -m --model + -p --pose + -l --link + -j --joint + -h --help + --force-version + --versions +" + +function _gz_model +{ + if [[ ${COMP_WORDS[COMP_CWORD]} == -* ]]; then + # Specify options (-*) word list for this subcommand + # NOTE: In Fortress+, add --headless-rendering. + # Update ../ign_TEST.cc accordingly. + COMPREPLY=($(compgen -W "$GZ_MODEL_WORDLIST" \ + -- "${COMP_WORDS[COMP_CWORD]}" )) + return + else + # Just use bash default auto-complete, because we never have two + # subcommands in the same line. If that is ever needed, change here to + # detect subsequent subcommands + COMPREPLY=($(compgen -o default -- "${COMP_WORDS[COMP_CWORD]}")) + return + fi +} + +function _gz_model_flags +{ + for word in $GZ_MODEL_WORDLIST; do + echo "$word" + done +} diff --git a/src/ign_TEST.cc b/src/ign_TEST.cc index abc5676f4d..a5f3917387 100644 --- a/src/ign_TEST.cc +++ b/src/ign_TEST.cc @@ -31,6 +31,8 @@ static const std::string kBinPath(PROJECT_BINARY_PATH); static const std::string kIgnCommand( std::string(BREW_RUBY) + std::string(IGN_PATH) + "/ign gazebo -s "); +static const std::string kIgnModelCommand( + std::string(BREW_RUBY) + std::string(IGN_PATH) + "/ign model "); ///////////////////////////////////////////////// std::string customExecStr(std::string _cmd) @@ -229,3 +231,35 @@ TEST(CmdLine, GazeboHelpVsCompletionFlags) EXPECT_NE(std::string::npos, script.find("--force-version")) << script; EXPECT_NE(std::string::npos, script.find("--versions")) << script; } + +////////////////////////////////////////////////// +/// \brief Check --help message and bash completion script for consistent flags +TEST(CmdLine, ModelHelpVsCompletionFlags) +{ + // Flags in help message + std::string helpOutput = customExecStr(kIgnModelCommand + " --help"); + + // Call the output function in the bash completion script + std::string scriptPath = ignition::common::joinPaths( + std::string(PROJECT_SOURCE_PATH), + "src", "cmd", "model.bash_completion.sh"); + + // Equivalent to: + // sh -c "bash -c \". /path/to/model.bash_completion.sh; _gz_model_flags\"" + std::string cmd = "bash -c \". " + scriptPath + "; _gz_model_flags\""; + std::cout << "Running command [" << cmd << "]" << std::endl; + std::string scriptOutput = customExecStr(cmd); + + // Tokenize script output + std::istringstream iss(scriptOutput); + std::vector flags((std::istream_iterator(iss)), + std::istream_iterator()); + + EXPECT_GT(flags.size(), 0u); + + // Match each flag in script output with help message + for (std::string flag : flags) + { + EXPECT_NE(std::string::npos, helpOutput.find(flag)) << helpOutput; + } +} From 3661b4a0588e2910f159c5c95d94b8d1624c0cc7 Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Tue, 7 Jun 2022 02:44:48 -0400 Subject: [PATCH 07/13] change flag var name Signed-off-by: Mabel Zhang --- src/cmd/model.bash_completion.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cmd/model.bash_completion.sh b/src/cmd/model.bash_completion.sh index b37c1ca394..fc06ededad 100644 --- a/src/cmd/model.bash_completion.sh +++ b/src/cmd/model.bash_completion.sh @@ -20,7 +20,7 @@ # This is a per-library function definition, used in conjunction with the # top-level entry point in ign-tools. -GZ_MODEL_WORDLIST=" +GZ_MODEL_COMPLETION_LIST=" --list -m --model -p --pose @@ -37,7 +37,7 @@ function _gz_model # Specify options (-*) word list for this subcommand # NOTE: In Fortress+, add --headless-rendering. # Update ../ign_TEST.cc accordingly. - COMPREPLY=($(compgen -W "$GZ_MODEL_WORDLIST" \ + COMPREPLY=($(compgen -W "$GZ_MODEL_COMPLETION_LIST" \ -- "${COMP_WORDS[COMP_CWORD]}" )) return else @@ -51,7 +51,7 @@ function _gz_model function _gz_model_flags { - for word in $GZ_MODEL_WORDLIST; do + for word in $GZ_MODEL_COMPLETION_LIST; do echo "$word" done } From 8b1d5d894b1f7c35a60b52d97fe25d0b7330b8bf Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Tue, 7 Jun 2022 02:55:09 -0400 Subject: [PATCH 08/13] do not hard code flags in test Signed-off-by: Mabel Zhang --- src/cmd/gazebo.bash_completion.sh | 64 ++++++++++++++----------- src/ign_TEST.cc | 79 +++++++++---------------------- 2 files changed, 59 insertions(+), 84 deletions(-) diff --git a/src/cmd/gazebo.bash_completion.sh b/src/cmd/gazebo.bash_completion.sh index 8608b057e4..2e7e8caf45 100644 --- a/src/cmd/gazebo.bash_completion.sh +++ b/src/cmd/gazebo.bash_completion.sh @@ -20,6 +20,34 @@ # This is a per-library function definition, used in conjunction with the # top-level entry point in ign-tools. +GZ_SIM_COMPLETION_LIST=" + -g + --iterations + --levels + --network-role + --network-secondaries + --record + --record-path + --record-resources + --record-topic + --log-overwrite + --log-compress + --playback + -r + -s + -v --verbose + --gui-config + --physics-engine + --render-engine + --render-engine-gui + --render-engine-server + --version + -z + -h --help + --force-version + --versions +" + # TODO(anyone): In Garden+, replace `gazebo` in function name to align with # subcommand, for ign-tools/etc/ign.bash_completion.sh to find this function. function _gz_gazebo @@ -28,33 +56,8 @@ function _gz_gazebo # Specify options (-*) word list for this subcommand # NOTE: In Fortress+, add --headless-rendering. # Update ../ign_TEST.cc accordingly. - COMPREPLY=($(compgen -W " - -g - --iterations - --levels - --network-role - --network-secondaries - --record - --record-path - --record-resources - --record-topic - --log-overwrite - --log-compress - --playback - -r - -s - -v --verbose - --gui-config - --physics-engine - --render-engine - --render-engine-gui - --render-engine-server - --version - -z - -h --help - --force-version - --versions - " -- "${COMP_WORDS[COMP_CWORD]}" )) + COMPREPLY=($(compgen -W "$GZ_SIM_COMPLETION_LIST" \ + -- "${COMP_WORDS[COMP_CWORD]}" )) return else # Just use bash default auto-complete, because we never have two @@ -64,3 +67,10 @@ function _gz_gazebo return fi } + +function _gz_sim_flags +{ + for word in $GZ_SIM_COMPLETION_LIST; do + echo "$word" + done +} diff --git a/src/ign_TEST.cc b/src/ign_TEST.cc index a5f3917387..70d212da12 100644 --- a/src/ign_TEST.cc +++ b/src/ign_TEST.cc @@ -170,66 +170,31 @@ TEST(CmdLine, ResourcePath) TEST(CmdLine, GazeboHelpVsCompletionFlags) { // Flags in help message - std::string output = customExecStr(kIgnCommand + " gazebo --help"); - EXPECT_NE(std::string::npos, output.find("-g")) << output; - EXPECT_NE(std::string::npos, output.find("--iterations")) << output; - EXPECT_NE(std::string::npos, output.find("--levels")) << output; - EXPECT_NE(std::string::npos, output.find("--network-role")) << output; - EXPECT_NE(std::string::npos, output.find("--network-secondaries")) << output; - EXPECT_NE(std::string::npos, output.find("--record")) << output; - EXPECT_NE(std::string::npos, output.find("--record-path")) << output; - EXPECT_NE(std::string::npos, output.find("--record-resources")) << output; - EXPECT_NE(std::string::npos, output.find("--record-topic")) << output; - EXPECT_NE(std::string::npos, output.find("--log-overwrite")) << output; - EXPECT_NE(std::string::npos, output.find("--log-compress")) << output; - EXPECT_NE(std::string::npos, output.find("--playback")) << output; - EXPECT_NE(std::string::npos, output.find("-r")) << output; - EXPECT_NE(std::string::npos, output.find("-s")) << output; - EXPECT_NE(std::string::npos, output.find("--verbose")) << output; - EXPECT_NE(std::string::npos, output.find("--gui-config")) << output; - EXPECT_NE(std::string::npos, output.find("--physics-engine")) << output; - EXPECT_NE(std::string::npos, output.find("--render-engine")) << output; - EXPECT_NE(std::string::npos, output.find("--render-engine-gui")) << output; - EXPECT_NE(std::string::npos, output.find("--render-engine-server")) << output; - EXPECT_NE(std::string::npos, output.find("--version")) << output; - EXPECT_NE(std::string::npos, output.find("-z")) << output; - EXPECT_NE(std::string::npos, output.find("--help")) << output; - EXPECT_NE(std::string::npos, output.find("--force-version")) << output; - EXPECT_NE(std::string::npos, output.find("--versions")) << output; - - // Flags in bash completion + std::string helpOutput = customExecStr(kIgnCommand + " gazebo --help"); + + // Call the output function in the bash completion script std::string scriptPath = ignition::common::joinPaths( std::string(PROJECT_SOURCE_PATH), "src", "cmd", "gazebo.bash_completion.sh"); - std::ifstream scriptFile(scriptPath); - std::string script((std::istreambuf_iterator(scriptFile)), - std::istreambuf_iterator()); - - EXPECT_NE(std::string::npos, script.find("-g")) << script; - EXPECT_NE(std::string::npos, script.find("--iterations")) << script; - EXPECT_NE(std::string::npos, script.find("--levels")) << script; - EXPECT_NE(std::string::npos, script.find("--network-role")) << script; - EXPECT_NE(std::string::npos, script.find("--network-secondaries")) << script; - EXPECT_NE(std::string::npos, script.find("--record")) << script; - EXPECT_NE(std::string::npos, script.find("--record-path")) << script; - EXPECT_NE(std::string::npos, script.find("--record-resources")) << script; - EXPECT_NE(std::string::npos, script.find("--record-topic")) << script; - EXPECT_NE(std::string::npos, script.find("--log-overwrite")) << script; - EXPECT_NE(std::string::npos, script.find("--log-compress")) << script; - EXPECT_NE(std::string::npos, script.find("--playback")) << script; - EXPECT_NE(std::string::npos, script.find("-r")) << script; - EXPECT_NE(std::string::npos, script.find("-s")) << script; - EXPECT_NE(std::string::npos, script.find("--verbose")) << script; - EXPECT_NE(std::string::npos, script.find("--gui-config")) << script; - EXPECT_NE(std::string::npos, script.find("--physics-engine")) << script; - EXPECT_NE(std::string::npos, script.find("--render-engine")) << script; - EXPECT_NE(std::string::npos, script.find("--render-engine-gui")) << script; - EXPECT_NE(std::string::npos, script.find("--render-engine-server")) << script; - EXPECT_NE(std::string::npos, script.find("--version")) << script; - EXPECT_NE(std::string::npos, script.find("-z")) << script; - EXPECT_NE(std::string::npos, script.find("--help")) << script; - EXPECT_NE(std::string::npos, script.find("--force-version")) << script; - EXPECT_NE(std::string::npos, script.find("--versions")) << script; + + // Equivalent to: + // sh -c "bash -c \". /path/to/gazebo.bash_completion.sh; _gz_sim_flags\"" + std::string cmd = "bash -c \". " + scriptPath + "; _gz_sim_flags\""; + std::cout << "Running command [" << cmd << "]" << std::endl; + std::string scriptOutput = customExecStr(cmd); + + // Tokenize script output + std::istringstream iss(scriptOutput); + std::vector flags((std::istream_iterator(iss)), + std::istream_iterator()); + + EXPECT_GT(flags.size(), 0u); + + // Match each flag in script output with help message + for (std::string flag : flags) + { + EXPECT_NE(std::string::npos, helpOutput.find(flag)) << helpOutput; + } } ////////////////////////////////////////////////// From d552310ef411096f5937751131d6597db9e400f6 Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Tue, 7 Jun 2022 03:10:49 -0400 Subject: [PATCH 09/13] do not print cmd Signed-off-by: Mabel Zhang --- src/ign_TEST.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/ign_TEST.cc b/src/ign_TEST.cc index 70d212da12..8adc158bed 100644 --- a/src/ign_TEST.cc +++ b/src/ign_TEST.cc @@ -180,7 +180,6 @@ TEST(CmdLine, GazeboHelpVsCompletionFlags) // Equivalent to: // sh -c "bash -c \". /path/to/gazebo.bash_completion.sh; _gz_sim_flags\"" std::string cmd = "bash -c \". " + scriptPath + "; _gz_sim_flags\""; - std::cout << "Running command [" << cmd << "]" << std::endl; std::string scriptOutput = customExecStr(cmd); // Tokenize script output @@ -212,7 +211,6 @@ TEST(CmdLine, ModelHelpVsCompletionFlags) // Equivalent to: // sh -c "bash -c \". /path/to/model.bash_completion.sh; _gz_model_flags\"" std::string cmd = "bash -c \". " + scriptPath + "; _gz_model_flags\""; - std::cout << "Running command [" << cmd << "]" << std::endl; std::string scriptOutput = customExecStr(cmd); // Tokenize script output From a8e589a82131a8801ec63db413099f5fba8024f5 Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Tue, 7 Jun 2022 04:07:36 -0400 Subject: [PATCH 10/13] change NOTE to TODO Signed-off-by: Mabel Zhang --- src/cmd/gazebo.bash_completion.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd/gazebo.bash_completion.sh b/src/cmd/gazebo.bash_completion.sh index 2e7e8caf45..7d6f6d3042 100644 --- a/src/cmd/gazebo.bash_completion.sh +++ b/src/cmd/gazebo.bash_completion.sh @@ -54,7 +54,7 @@ function _gz_gazebo { if [[ ${COMP_WORDS[COMP_CWORD]} == -* ]]; then # Specify options (-*) word list for this subcommand - # NOTE: In Fortress+, add --headless-rendering. + # TODO(anyone): In Fortress+, add --headless-rendering. # Update ../ign_TEST.cc accordingly. COMPREPLY=($(compgen -W "$GZ_SIM_COMPLETION_LIST" \ -- "${COMP_WORDS[COMP_CWORD]}" )) From 9b78e35c14b46a55875be62175bc053aaa512609 Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Tue, 7 Jun 2022 04:10:45 -0400 Subject: [PATCH 11/13] remove copy paste error Signed-off-by: Mabel Zhang --- src/cmd/model.bash_completion.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/cmd/model.bash_completion.sh b/src/cmd/model.bash_completion.sh index fc06ededad..6ddc4f4128 100644 --- a/src/cmd/model.bash_completion.sh +++ b/src/cmd/model.bash_completion.sh @@ -35,8 +35,6 @@ function _gz_model { if [[ ${COMP_WORDS[COMP_CWORD]} == -* ]]; then # Specify options (-*) word list for this subcommand - # NOTE: In Fortress+, add --headless-rendering. - # Update ../ign_TEST.cc accordingly. COMPREPLY=($(compgen -W "$GZ_MODEL_COMPLETION_LIST" \ -- "${COMP_WORDS[COMP_CWORD]}" )) return From 31c92f75f1b0cba44d40cdaf2e8f558c047d96c7 Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Tue, 7 Jun 2022 12:05:27 -0400 Subject: [PATCH 12/13] extra line Signed-off-by: Mabel Zhang --- src/cmd/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cmd/CMakeLists.txt b/src/cmd/CMakeLists.txt index b61fee1245..11e7ef7e00 100644 --- a/src/cmd/CMakeLists.txt +++ b/src/cmd/CMakeLists.txt @@ -118,7 +118,6 @@ configure_file( "model.yaml.in" "${CMAKE_BINARY_DIR}/test/conf/model${PROJECT_VERSION_MAJOR}.yaml" @ONLY) - #=============================================================================== # Bash completion From 7c0f3b9bcffce2a7b9b3feca7eb897c1d6ff0011 Mon Sep 17 00:00:00 2001 From: Louise Poubel Date: Tue, 14 Jun 2022 16:59:20 -0700 Subject: [PATCH 13/13] comment and const ref Signed-off-by: Louise Poubel --- CMakeLists.txt | 2 ++ src/ign_TEST.cc | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6af26db0b0..4e2f9e21cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -136,6 +136,8 @@ set(IGN_MATH_VER ${ignition-math6_VERSION_MAJOR}) ign_find_package(ignition-tools REQUIRED PKGCONFIG "ignition-tools") +# Note that CLI files are installed regardless of whether the dependency is +# available during build time set(IGN_TOOLS_VER 1) #-------------------------------------- diff --git a/src/ign_TEST.cc b/src/ign_TEST.cc index 8adc158bed..a66def21b3 100644 --- a/src/ign_TEST.cc +++ b/src/ign_TEST.cc @@ -190,7 +190,7 @@ TEST(CmdLine, GazeboHelpVsCompletionFlags) EXPECT_GT(flags.size(), 0u); // Match each flag in script output with help message - for (std::string flag : flags) + for (const auto &flag : flags) { EXPECT_NE(std::string::npos, helpOutput.find(flag)) << helpOutput; } @@ -221,7 +221,7 @@ TEST(CmdLine, ModelHelpVsCompletionFlags) EXPECT_GT(flags.size(), 0u); // Match each flag in script output with help message - for (std::string flag : flags) + for (const auto &flag : flags) { EXPECT_NE(std::string::npos, helpOutput.find(flag)) << helpOutput; }