Skip to content

Add --all alias to commands that include hidden nodes, topics, or services #1302

Description

@sloretz

Commands in ros2cli use different option names to include hidden entities. For example, ros2 node list and ros2 lifecycle nodes use -a / --all, ros2 node info uses --include-hidden, and other commands use --include-hidden-nodes, --include-hidden-topics, or --include-hidden-services.

Add --all (and -a) as an alias to the following files so users can pass --all consistently across commands:

  • ros2node/ros2node/verb/info.py
  • ros2lifecycle/ros2lifecycle/verb/get.py
  • ros2lifecycle/ros2lifecycle/verb/set.py
  • ros2param/ros2param/verb/delete.py
  • ros2param/ros2param/verb/describe.py
  • ros2param/ros2param/verb/dump.py
  • ros2param/ros2param/verb/get.py
  • ros2param/ros2param/verb/list.py
  • ros2param/ros2param/verb/load.py
  • ros2param/ros2param/verb/set.py
  • ros2topic/ros2topic/command/topic.py
  • ros2topic/ros2topic/verb/find.py
  • ros2topic/ros2topic/verb/list.py
  • ros2service/ros2service/command/service.py
  • ros2service/ros2service/verb/find.py
  • ros2service/ros2service/verb/list.py

(Note: Skip ros2lifecycle/ros2lifecycle/verb/list.py because it already uses -a / --all to display all transitions.)

Example: How to add the alias

Keep the existing long option first (so argparse keeps the same args.<attribute> destination name) and add '--all' and '-a':

# Before:
parser.add_argument(
    '--include-hidden-topics', action='store_true',
    help='Consider hidden topics as well')

# After:
parser.add_argument(
    '--include-hidden-topics', '--all', action='store_true',
    help='Consider hidden topics as well')

Example: How to add a test

You can test argument parsing in the package's test/ folder using argparse.ArgumentParser:

import argparse
from ros2topic.verb.list import ListVerb


def test_list_all_alias():
    parser = argparse.ArgumentParser()
    verb = ListVerb()
    verb.add_arguments(parser, 'ros2 topic list')
    args = parser.parse_args(['--all'])
    assert args.include_hidden_topics is True

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions