Skip to content

Commit

Permalink
Add arg to pass launch arg via yaml file
Browse files Browse the repository at this point in the history
Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>
  • Loading branch information
tonynajjar committed Jun 26, 2024
1 parent 6863994 commit 8cbb490
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ros2launch/ros2launch/command/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import os
import sys
import yaml

from ament_index_python.packages import PackageNotFoundError
try:
Expand Down Expand Up @@ -102,6 +103,10 @@ def add_arguments(self, parser, cli_name):
help=('Regex pattern for filtering which executables the --launch-prefix is applied '
'to by matching the executable name.')
)
parser.add_argument(
'--launch-arguments-file',
help='Path to a YAML file containing launch arguments'
)
arg = parser.add_argument(
'package_name',
help='Name of the ROS package which contains the launch file')
Expand Down Expand Up @@ -132,6 +137,14 @@ def main(self, *, parser, args):

path = None
launch_arguments = []
if args.launch_arguments_file:
with open(args.launch_arguments_file, 'r') as file:
yaml_args = yaml.safe_load(file)
if isinstance(yaml_args, dict):
for key, value in yaml_args.items():
launch_arguments.append(f"{key}:={value}")
else:
raise RuntimeError('The launch arguments file must contain a dictionary.')
if mode == 'single file':
# TODO(wjwwood): figure out how to have argparse and argcomplete
# handle this, for now, hidden feature.
Expand Down

0 comments on commit 8cbb490

Please sign in to comment.