Closed osrf-migration closed 1 year ago
To start investigating this, I looked briefly at ros2cli
, since it does a very good job of tab-completing in bash. It uses argcomplete, which is based in python and automatically works for packages that express their arguments using argparse. The following files is all that is needed to enable bash-completion:
That command is sourced as part of the general ros2 setup script, I believe because of the following configuration file:
If only we could just use argcomplete
for ign
! Unfortunately it does not currently use python. ign
uses Ruby to look for *.yaml
files in the IGN_CONFIG_PATH
and parses these YAML files to determine the list of commands that can be executed. These command are implemented as Ruby files that either dlopen
a c++ library to call a function or pass the CLI arguments to a C++ executable.
I think a first step would be to implement autocomplete for just the names of commands available in IGN_CONFIG_PATH
. Once that is working, we can figure out how support autocomplete for the arguments to each command.
An additional reference is the gz completion script used in gazebo classic.
Our executables are currently using a fork of cli11 for argument parsing, which has an open feature request to support autocompletion: https://github.com/CLIUtils/CLI11/issues/343.
If only we could just use
argcomplete
forign
! Unfortunately it does not currently use python.
There is a way to use argcomplete
with programs not written in python using the --external-argcomplete-script
, but it requires writing a python script with the argument parsing logic replicated using argparse
.
I've started in https://github.com/ignitionrobotics/ign-tools/pull/77 by porting a portion of the gz
completion script that autocompletes from a list of valid ign
commands determined with ign --commands
. It is a minimal set of functionality to demonstrate the approach.
If only we could just use
argcomplete
forign
! Unfortunately it does not currently use python.ign
uses Ruby to look for*.yaml
files in theIGN_CONFIG_PATH
and parses these YAML files to determine the list of commands that can be executed. These command are implemented as Ruby files that eitherdlopen
a c++ library to call a function or pass the CLI arguments to a C++ executable.
Actually the Ruby class also supports shell completion.
But is there any reason to stay with Ruby? The Ruby cmd classes could be implemented in Python with the same mechanism (argparse
with argcomplete
) as in ROS2. Also, I think there are more people familiar with Python than Ruby.
I'm not sure if this is the only use of Ruby in Ignition but replacing Ruby would also reduce the number of dependencies (Python is needed for the (new) scripting interface via pybind11
anyway).
But is there any reason to stay with Ruby?
One reason at the moment is that we don't have the time to port it to another language, which would be a large effort, so we'd need a strong reason to do so.
I'm not sure if this is the only use of Ruby in Ignition
Followup tasks to #87, which adds bash completion to second-level flags, i.e. cmd subcommand --flag
:
/usr/share/bash-completion/completions/ign
in release repo, like the top-level command was installed https://github.com/gazebo-release/gz-tools-release/pull/4 , so that second-level flag completion is automatically available. Currently, it requires users manually source a script installed to install/share/gz/gz#.completion
. Details in https://github.com/gazebosim/gz-tools/pull/87#discussion_r887208945
log
(in gz-transport) and fuel
(in gz-fuel-tools), see https://github.com/gazebosim/gz-transport/pull/312#issuecomment-1133524638As of https://github.com/gazebosim/gz-transport/pull/451, I believe all commands have bash completion now, so I'll go ahead and close this issue.
Original report (archived issue) by Louise Poubel (Bitbucket: chapulina, GitHub: chapulina).
Pressing tab twice should complete with possible commands. Take the
gz
tool for example, pressing tab twice displays options such ascamera
,topic
, etc.