Skip to content

Add --timeout alias to ros2 topic pub and ros2 param list #1305

Description

@sloretz

Most ros2cli commands use --timeout to specify a maximum wait time in seconds, but ros2 topic pub uses --max-wait-time-secs and ros2 param list only accepts --service-timeout.

Modify the following files to accept --timeout as an alias:

  • ros2topic/ros2topic/verb/pub.py
  • ros2param/ros2param/verb/list.py

Example: How to add the alias

Keep the existing option name first (so the args attribute name stays the same) and add '--timeout':

# Before (in ros2topic/ros2topic/verb/pub.py):
parser.add_argument(
    '--max-wait-time-secs',
    dest='max_wait_time_secs', type=positive_float, default=None,
    help=...)

# After:
parser.add_argument(
    '--max-wait-time-secs', '--timeout',
    dest='max_wait_time_secs', type=positive_float, default=None,
    help=...)

Example: How to add a test

Add a test in ros2topic/test/ (and ros2param/test/test_verb_list.py) to check that --timeout sets the expected attribute:

import argparse
from ros2topic.verb.pub import PubVerb


def test_pub_timeout_alias():
    parser = argparse.ArgumentParser()
    verb = PubVerb()
    verb.add_arguments(parser, 'ros2 topic pub')
    args = parser.parse_args(['/chatter', 'std_msgs/msg/String', '--timeout', '2.5'])
    assert args.max_wait_time_secs == 2.5

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions