Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions ros2action/ros2action/verb/send_goal.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

from argparse import ArgumentTypeError
from argparse import FileType

import signal

Expand Down Expand Up @@ -61,6 +62,9 @@ def add_arguments(self, parser, cli_name):
group.add_argument(
'--stdin', action='store_true',
help='Read goal from standard input')
group.add_argument(
'--goal-file', metavar='FILE', type=FileType('r'),
Comment thread
sylvesterkaczmarek marked this conversation as resolved.
Outdated
help='Read goal request values from a YAML file')
arg.completer = ActionGoalPrototypeCompleter(action_type_key='action_type')
parser.add_argument(
'-f', '--feedback', action='store_true',
Expand All @@ -81,6 +85,9 @@ def main(self, *, args):

if args.stdin:
goal = collect_stdin()
elif args.goal_file:
with args.goal_file:
goal = args.goal_file.read()
Comment thread
sylvesterkaczmarek marked this conversation as resolved.
Outdated
else:
goal = args.goal

Expand Down
43 changes: 43 additions & 0 deletions ros2action/test/test_send_goal_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2026 Open Source Robotics Foundation, Inc.
Comment thread
sylvesterkaczmarek marked this conversation as resolved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from argparse import ArgumentParser
from unittest.mock import patch

from ros2action.verb.send_goal import SendGoalVerb


def test_send_goal_reads_goal_file(tmp_path):
goal_file = tmp_path / 'goal.yaml'
goal_file.write_text('order: 7\n', encoding='utf-8')

parser = ArgumentParser()
verb = SendGoalVerb()
verb.add_arguments(parser, 'action')
args = parser.parse_args([
'/fibonacci',
'example_interfaces/action/Fibonacci',
'--goal-file', str(goal_file),
])

with patch('ros2action.verb.send_goal.send_goal') as mock_send_goal:
verb.main(args=args)

mock_send_goal.assert_called_once_with(
'/fibonacci',
'example_interfaces/action/Fibonacci',
'order: 7\n',
None,
None,
)