diff --git a/ros2cli/ros2cli/node/strategy.py b/ros2cli/ros2cli/node/strategy.py index 8f3e46cca..ac1cdea9e 100644 --- a/ros2cli/ros2cli/node/strategy.py +++ b/ros2cli/ros2cli/node/strategy.py @@ -22,20 +22,21 @@ class NodeStrategy: - def __init__(self, args): + def __init__(self, args, *, node_name=None): use_daemon = not getattr(args, 'no_daemon', False) if use_daemon and is_daemon_running(args): self._daemon_node = DaemonNode(args) self._direct_node = None if not self._daemon_node.connected: - self._direct_node = DirectNode(args) + self._direct_node = DirectNode(args, node_name=node_name) self._daemon_node = None else: if use_daemon: spawn_daemon(args) - self._direct_node = DirectNode(args) + self._direct_node = DirectNode(args, node_name=node_name) self._daemon_node = None self._args = args + self._node_name = node_name self._in_scope = False @property @@ -45,7 +46,7 @@ def daemon_node(self): @property def direct_node(self): if self._direct_node is None: - self._direct_node = DirectNode(self._args) + self._direct_node = DirectNode(self._args, node_name=self._node_name) if self._in_scope: self._direct_node.__enter__() return self._direct_node diff --git a/ros2topic/ros2topic/verb/echo.py b/ros2topic/ros2topic/verb/echo.py index 0bce1711d..edd8b8917 100644 --- a/ros2topic/ros2topic/verb/echo.py +++ b/ros2topic/ros2topic/verb/echo.py @@ -110,6 +110,9 @@ def add_arguments(self, parser, cli_name): parser.add_argument( '--clear', '-c', action='store_true', help='Clear screen before printing next message') + parser.add_argument( + '-n', '--node-name', type=str, default=None, + help='The name of the echoing node; by default, will be a hidden node name') def choose_qos(self, node, args): @@ -200,7 +203,7 @@ def main(self, *, args): self.include_message_info = args.include_message_info - with NodeStrategy(args) as node: + with NodeStrategy(args, node_name=args.node_name) as node: qos_profile = self.choose_qos(node, args)