Skip to content

Commit 9f6c337

Browse files
authored
[ros2lifecycle] Only return the state for the node requested (#266)
* [ros2lifecycle] Only return the state for the node requested Previously, the 'get' verb was returning the state for all lifecycle nodes. Signed-off-by: Jacob Perron <[email protected]> * Fix logic to handle optional positional argument Signed-off-by: Jacob Perron <[email protected]> * Clarfiy 'lifecycle get' behavior in documentation Signed-off-by: Jacob Perron <[email protected]>
1 parent 0b75d70 commit 9f6c337

File tree

1 file changed

+7
-3
lines changed
  • ros2lifecycle/ros2lifecycle/verb

1 file changed

+7
-3
lines changed

ros2lifecycle/ros2lifecycle/verb/get.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@
2525

2626

2727
class GetVerb(VerbExtension):
28-
"""Get lifecycle state."""
28+
"""Get lifecycle state for one or more nodes."""
2929

3030
def add_arguments(self, parser, cli_name): # noqa: D102
3131
add_arguments(parser)
3232
arg = parser.add_argument(
33-
'node_name', nargs='?', help='Name of the ROS node')
33+
'node_name', nargs='?', help='Name of the ROS node. '
34+
'If no name is provided, then get the state for all nodes.')
3435
arg.completer = NodeNameCompleter(
3536
include_hidden_nodes_key='include_hidden_nodes')
3637
parser.add_argument(
@@ -47,9 +48,12 @@ def main(self, *, args): # noqa: D102
4748
if node_name:
4849
if node_name not in node_names:
4950
return 'Node not found'
51+
nodes_to_query = [node_name]
52+
else:
53+
nodes_to_query = node_names
5054

5155
with DirectNode(args) as node:
52-
states = call_get_states(node=node, node_names=node_names)
56+
states = call_get_states(node=node, node_names=nodes_to_query)
5357

5458
# output exceptions
5559
for node_name in sorted(states.keys()):

0 commit comments

Comments
 (0)