Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add regex filter for selective launch-prefix application #261

Merged
merged 7 commits into from
Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion ros2launch/ros2launch/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,12 @@ def launch_a_launch_file(

# If 'launch-prefix' launch file argument is also provided in the user input,
# the 'launch-prefix' option is applied since the last duplicate argument is used
if args is not None and args.launch_prefix is not None and len(args.launch_prefix) > 0:
if args and args.launch_prefix:
launch_file_arguments.append(f'launch-prefix:={args.launch_prefix}')

if args and args.launch_prefix_filter:
launch_file_arguments.append(f'launch-prefix-filter:={args.launch_prefix_filter}')

launch_service = launch.LaunchService(
argv=launch_file_arguments,
noninteractive=noninteractive,
Expand Down
9 changes: 9 additions & 0 deletions ros2launch/ros2launch/command/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ def add_arguments(self, parser, cli_name):
'Command must be wrapped in quotes if it contains spaces '
"(e.g. --launch-prefix 'xterm -e gdb -ex run --args')."
)
parser.add_argument(
'--launch-prefix-filter',
help=('Regex pattern for filtering which executables the --launch-prefix is applied '
'to by matching the executable name.')
)
arg = parser.add_argument(
'package_name',
help='Name of the ROS package which contains the launch file')
Expand Down Expand Up @@ -153,6 +158,10 @@ def main(self, *, parser, args):
raise RuntimeError('unexpected mode')
launch_arguments.extend(args.launch_arguments)

if args.launch_prefix is None and args.launch_prefix_filter is not None:
raise RuntimeError(
'--launch-prefix must be specified if --launch-prefix-filter is provided')

if args.show_all_subprocesses_output:
os.environ['OVERRIDE_LAUNCH_PROCESS_OUTPUT'] = 'both'
if args.print:
Expand Down