Skip to content

Commit

Permalink
Migrate CLI
Browse files Browse the repository at this point in the history
Signed-off-by: methylDragon <methylDragon@gmail.com>
  • Loading branch information
methylDragon committed Jun 16, 2022
1 parent bd7ba5b commit 24e3a9f
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 66 deletions.
1 change: 1 addition & 0 deletions Migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ release will remove the deprecated code.
## Gazebo Tools 1.X to 2.X

* The environment variable `IGN_CONFIG_PATH` is deprecated. Use `GZ_CONFIG_PATH` instead.
* The `ign` command line executable is deprecated. Use `gz` instead.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ Ubuntu Bionic | [![Build Status](https://build.osrfoundation.org/buildStatus/ico
Homebrew | [![Build Status](https://build.osrfoundation.org/buildStatus/icon?job=ignition_tools-ci-ign-tools2-homebrew-amd64)](https://build.osrfoundation.org/job/ignition_tools-ci-ign-tools2-homebrew-amd64)
Windows | [![Build Status](https://build.osrfoundation.org/buildStatus/icon?job=ign_tools-ign-1-win)](https://build.osrfoundation.org/job/ign_tools-ign-1-win)

Ignition tools provide the `ign` command line tool that accepts multiple
Ignition tools provide the `gz` command line tool that accepts multiple
subcommands. Each subcommand is implemented in a plugin that belongs to a
specific Ignition project. For example, all the commands that start with
`ign topic ...` will be implemented by the Gazebo Transport library.
`gz topic ...` will be implemented by the Gazebo Transport library.

[http://gazebosim.org](http://gazebosim.org)

Expand All @@ -32,7 +32,7 @@ We recommend following the Binary Installation instructions to get up and runnin

The Source Installation instructions should be used if you need the very latest software improvements, you need to modify the code, or you plan to make a contribution.

Windows support: Currently, the library builds on Windows, but the `ign` command-line tool is not readily functional. We are investigating this.
Windows support: Currently, the library builds on Windows, but the `gz` command-line tool is not readily functional. We are investigating this.

## Binary Installation

Expand All @@ -53,8 +53,8 @@ Miniconda suffices.

Create if necessary, and activate a Conda environment:
```
conda create -n ign-ws
conda activate ign-ws
conda create -n gz-ws
conda activate gz-ws
```

Install `ignition-tools`:
Expand Down Expand Up @@ -90,9 +90,9 @@ sudo make install

### Bash auto-completion

Source the [etc/ign.bash_completion.sh](etc/ign.bash_completion.sh) script in your bash terminal window to enable auto-complete:
Source the [etc/gz.bash_completion.sh](etc/gz.bash_completion.sh) script in your bash terminal window to enable auto-complete:
~~~
. etc/ign.bash_completion.sh
. etc/gz.bash_completion.sh
~~~

### Uninstallation
Expand All @@ -112,8 +112,8 @@ Miniconda suffices.

Create if necessary, and activate a Conda environment:
```
conda create -n ign-ws
conda activate ign-ws
conda create -n gz-ws
conda activate gz-ws
```

Install prerequisites:
Expand Down
6 changes: 3 additions & 3 deletions cmake/run_test.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This script is part of the unit test mechanism for ign-tools.
execute_process(COMMAND ruby ${IGN_SCRIPT}
execute_process(COMMAND ruby ${GZ_SCRIPT}
${TEST_NAME}
OUTPUT_VARIABLE TEST_OUTPUT
ERROR_VARIABLE TEST_ERROR)
Expand All @@ -12,8 +12,8 @@ execute_process(COMMAND
"../test_results/${TEST_NAME}.xml"
)

if (${TEST_OUTPUT} MATCHES "Test executed" AND NOT
((${TEST_OUTPUT} MATCHES "Library error") OR
if (${TEST_OUTPUT} MATCHES "Test executed" AND NOT
((${TEST_OUTPUT} MATCHES "Library error") OR
(${TEST_ERROR} MATCHES "Library error")))
execute_process(COMMAND
${CMAKE_COMMAND} -E copy
Expand Down
6 changes: 3 additions & 3 deletions etc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ install(FILES
${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}/gz)

configure_file(
"ign.bash_completion.sh"
"${CMAKE_CURRENT_BINARY_DIR}/ign${PROJECT_MAJOR_VERSION}.bash_completion.sh" @ONLY)
"gz.bash_completion.sh"
"${CMAKE_CURRENT_BINARY_DIR}/gz${PROJECT_MAJOR_VERSION}.bash_completion.sh" @ONLY)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/ign${PROJECT_MAJOR_VERSION}.bash_completion.sh
${CMAKE_CURRENT_BINARY_DIR}/gz${PROJECT_MAJOR_VERSION}.bash_completion.sh
DESTINATION
${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}/gz/gz${PROJECT_MAJOR_VERSION}.completion.d)
18 changes: 9 additions & 9 deletions etc/gz.bash_completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
# limitations under the License.
#

# ign bash completion
# gz bash completion

function _ign
function _gz
{
local prev cur cmd opts
local ign="$1"
local gz="$1"
cur="$2"
prev="$3"

Expand All @@ -38,12 +38,12 @@ function _ign
fi
done

# On a word after top-level command ign. It may be an option (-*)
if [[ "$cur" == -* ]] || [[ "$prev" != "ign" ]]; then
# On a word after top-level command gz. It may be an option (-*)
if [[ "$cur" == -* ]] || [[ "$prev" != "gz" ]]; then

# Subcommand is help
if [[ "$cmd" == "help" ]]; then
opts=$(ign --commands)
opts=$(gz --commands)

# Subcommand is a library name or an option (-*)
else
Expand All @@ -60,11 +60,11 @@ function _ign
return
fi

# on first word, top-level command (ign)
# on first word, top-level command (gz)
else
opts="$(ign --commands) help"
opts="$(gz --commands) help"
fi

COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
}
complete -F "_ign" "ign"
complete -F "_gz" "gz"
67 changes: 41 additions & 26 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ else()
set(ENV_PATH_DELIMITER ":")
endif()

set(executable_name "ign")
set(executable_name "gz")

if(WIN32)
set(executable_name "ign.rb")
set(executable_name "gz.rb")
endif()

if(MSVC)
Expand All @@ -34,9 +34,9 @@ if(MSVC)
target_compile_options(backward PUBLIC /wd4267)
target_compile_options(backward PUBLIC /wd4996)
endif()
install (TARGETS backward
install (TARGETS backward
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
RUNTIME DESTINATION ${BIN_INSTALL_DIR})

#===============================================================================
Expand All @@ -48,42 +48,57 @@ else()
set(backward_library_name $<TARGET_FILE_NAME:backward>)
endif()

# Two steps to create `ign`, First using `configure_file`, to interpolate cmake variables. Then
# Two steps to create `gz`, First using `configure_file`, to interpolate cmake variables. Then
# use `file(GENERATE ...)` to use generator expressions
set(ign_script_configured ${PROJECT_BINARY_DIR}/${executable_name}_before_gen)
set(ign_script_generated ${PROJECT_BINARY_DIR}/$<CONFIG>/${executable_name})
set(gz_script_configured ${PROJECT_BINARY_DIR}/${executable_name}_before_gen)
set(gz_script_generated ${PROJECT_BINARY_DIR}/$<CONFIG>/${executable_name})

configure_file(ign.in ${ign_script_configured})
file(GENERATE OUTPUT ${ign_script_generated} INPUT ${ign_script_configured})
install (PROGRAMS ${ign_script_generated} DESTINATION ${BIN_INSTALL_DIR})
configure_file(gz.in ${gz_script_configured})
file(GENERATE OUTPUT ${gz_script_generated} INPUT ${gz_script_configured})
install (PROGRAMS ${gz_script_generated} DESTINATION ${BIN_INSTALL_DIR})

if(WIN32)
# On Windows also install the executable as ign
# to permit to invoke ign via Git Bash
# On Windows also install the executable as gz
# to permit to invoke gz via Git Bash
# see https://github.com/gazebosim/gz-tools/issues/70
install (PROGRAMS ${ign_script_generated} DESTINATION ${BIN_INSTALL_DIR} RENAME ign)

# On Windows also install the ign.bat wrapper script to permit to
# invoke ign via Command Prompt or Powershell
install (PROGRAMS ign.bat DESTINATION ${BIN_INSTALL_DIR})
install(PROGRAMS ${gz_script_generated} DESTINATION ${BIN_INSTALL_DIR} RENAME gz)

# On Windows also install the gz.bat wrapper script to permit to
# invoke gz via Command Prompt or Powershell
install(PROGRAMS gz.bat DESTINATION ${BIN_INSTALL_DIR})

# TODO(CH3): Deprecated. Tick-tock the ign executable
# This is exceptionally scuffed
install(PROGRAMS ${ign_script_generated} DESTINATION ${BIN_INSTALL_DIR} RENAME ign)
install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
${CMAKE_INSTALL_PREFIX}/${BIN_INSTALL_DIR}/gz.bat
${PROJECT_BINARY_DIR}/ign.bat)")
install(PROGRAMS ${PROJECT_BINARY_DIR}/ign.bat DESTINATION ${BIN_INSTALL_DIR})
else()
# TODO(CH3): Deprecated. Tick-tock the ign executable with symlink
# This is exceptionally scuffed
install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
${CMAKE_INSTALL_PREFIX}/${BIN_INSTALL_DIR}/gz
${PROJECT_BINARY_DIR}/ign)")
install(PROGRAMS ${PROJECT_BINARY_DIR}/ign DESTINATION ${BIN_INSTALL_DIR})
endif()

#===============================================================================
# BEGIN TEST ign command
# BEGIN TEST gz command
# Generate the ruby script for internal testing.
if(BUILD_TESTING)
set(backward_library_name $<TARGET_FILE:backward>)
set(ign_script_configured_test ${PROJECT_BINARY_DIR}/test/bin/${executable_name}_before_gen)
set(ign_script_generated_test ${PROJECT_BINARY_DIR}/$<CONFIG>/test/bin/${executable_name})
set(gz_script_configured_test ${PROJECT_BINARY_DIR}/test/bin/${executable_name}_before_gen)
set(gz_script_generated_test ${PROJECT_BINARY_DIR}/$<CONFIG>/test/bin/${executable_name})

# Two steps to create `ign`, First using `configure_file`, to interpolate cmake variables. Then
# Two steps to create `gz`, First using `configure_file`, to interpolate cmake variables. Then
# use `file(GENERATE ...)` to use generator expressions
configure_file(ign.in ${ign_script_configured_test})
file(GENERATE OUTPUT ${ign_script_generated_test} INPUT ${ign_script_configured_test})
configure_file(gz.in ${gz_script_configured_test})
file(GENERATE OUTPUT ${gz_script_generated_test} INPUT ${gz_script_configured_test})

set(TEST_NAME UNIT_ign_TEST)
set(TEST_NAME UNIT_gz_TEST)

set(ign_library_path "${PROJECT_SOURCE_DIR}/src/cmd${TEST_NAME}.rb")
set(gz_library_path "${PROJECT_SOURCE_DIR}/src/cmd${TEST_NAME}.rb")

set(yaml_output_dir "${PROJECT_BINARY_DIR}/test/conf" )
set(yaml_output_configured_test "${yaml_output_dir}/${TEST_NAME}.yaml.configured")
Expand Down Expand Up @@ -111,7 +126,7 @@ if(BUILD_TESTING)
NAME ${TEST_NAME}
COMMAND ${CMAKE_COMMAND}
-DTEST_NAME=${TEST_NAME}
-DIGN_SCRIPT=${ign_script_generated_test}
-DGZ_SCRIPT=${gz_script_generated_test}
-P ${PROJECT_SOURCE_DIR}/cmake/run_test.cmake
)

Expand Down
4 changes: 2 additions & 2 deletions src/UNIT_gz_TEST.yaml.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
format: 1.0.0
library_name: @PROJECT_NAME@
library_version: ''
library_path: @ign_library_path@
library_path: @gz_library_path@
commands:
- UNIT_ign_TEST : Test command
- UNIT_gz_TEST : Test command
---

2 changes: 1 addition & 1 deletion src/cmdUNIT_gz_TEST.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
require 'optparse'

# Constants.
COMMANDS = { 'tools' => 'Test ign tools.\n\n' }.freeze
COMMANDS = { 'tools' => 'Test gz tools.\n\n' }.freeze

# Test Cmd class
class Cmd
Expand Down
4 changes: 2 additions & 2 deletions src/gz.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@echo off
REM %~dp0 is the directory in which this bat script is, see
REM https://stackoverflow.com/questions/112055/what-does-d0-mean-in-a-windows-batch-file
REM %* redirects the arguments to the output, see
REM %* redirects the arguments to the output, see
REM https://serverfault.com/questions/22443/do-windows-batch-files-have-a-construction/22541#22541
ruby %~dp0\ign %*
ruby %~dp0\gz %*
18 changes: 9 additions & 9 deletions src/gz.in
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ conf_dirs.each do |conf_directory|
end
end

# Check that we have at least one configuration file with ign commands.
# Check that we have at least one configuration file with gz commands.
unless yaml_found
puts "I cannot find any available 'ign' command:\n"\
"\t* Did you install any ignition library?\n"\
puts "I cannot find any available 'gz' command:\n"\
"\t* Did you install any Gazebo library?\n"\
"\t* Did you set the GZ_CONFIG_PATH environment variable?\n"\
"\t E.g.: export GZ_CONFIG_PATH=$HOME/local/share/ignition\n"
"\t E.g.: export GZ_CONFIG_PATH=$HOME/local/share/gz\n"
exit(-1)
end

Expand All @@ -176,9 +176,9 @@ commands = sorted_commands
# puts commands

# Read the command line arguments.
usage = 'The \'ign\' command provides a command line interface to the ignition'\
" tools.\n\n"\
" ign <command> [options]\n\n"\
usage = 'The \'gz\' command provides a command line interface to the Gazebo'\
" Tools.\n\n"\
" gz <command> [options]\n\n"\
"List of available commands:\n\n"\
" help: Print this help text.\n"

Expand All @@ -200,7 +200,7 @@ usage += "\nOptions:\n\n"\
" --versions Show the available versions.\n"\
' --commands Show the available commands.'

usage += "\nUse 'ign help <command>' to print help for a command.\n"
usage += "\nUse 'gz help <command>' to print help for a command.\n"

OptionParser.new do |opts|
opts.banner = usage
Expand Down Expand Up @@ -301,6 +301,6 @@ require cmd_rb_library
cmd = Cmd.new

# Set the process title to something nice.
Process.setproctitle("ign #{ARGV.join(' ')}")
Process.setproctitle("gz #{ARGV.join(' ')}")

cmd.execute(ARGV)
2 changes: 1 addition & 1 deletion tools/junit_fail.xml.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="1" failures="1" disabled="0" errors="0" timestamp="@TEST_TIME@" time="0" name="AllTests">
<testsuite name="@TEST_NAME@" tests="1" failures="1" disabled="0" errors="0" time="0">
<testcase name="ign_script" status="run" time="0" classname="@TEST_NAME@">
<testcase name="GZ_SCRIPT" status="run" time="0" classname="@TEST_NAME@">
<failure type="Standard" message="@TEST_NAME@ failed." />
</testcase>
</testsuite>
Expand Down
2 changes: 1 addition & 1 deletion tools/junit_pass.xml.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="1" failures="0" disabled="0" errors="0" timestamp="@TEST_TIME@" time="0" name="AllTests">
<testsuite name="@TEST_NAME@" tests="1" failures="0" disabled="0" errors="0" time="0">
<testcase name="ign_script" status="run" time="0" classname="@TEST_NAME@" />
<testcase name="GZ_SCRIPT" status="run" time="0" classname="@TEST_NAME@" />
</testsuite>
</testsuites>

0 comments on commit 24e3a9f

Please sign in to comment.