|
16 | 16 | from typing import Optional |
17 | 17 | from typing import TypeVar |
18 | 18 |
|
| 19 | +import argcomplete |
| 20 | + |
19 | 21 | import rclpy |
20 | 22 | from rclpy.node import Node |
21 | 23 | from rclpy.qos import QoSProfile |
|
25 | 27 | from ros2topic.api import add_qos_arguments |
26 | 28 | from ros2topic.api import positive_float |
27 | 29 | from ros2topic.api import profile_configure_short_keys |
28 | | -from ros2topic.api import TopicMessagePrototypeCompleter |
| 30 | +from ros2topic.api import TopicMessagePrototypeCompleter, YamlCompletionFinder |
29 | 31 | from ros2topic.api import TopicNameCompleter |
30 | 32 | from ros2topic.api import TopicTypeCompleter |
31 | 33 | from ros2topic.verb import VerbExtension |
@@ -108,6 +110,10 @@ def add_arguments(self, parser, cli_name): |
108 | 110 | parser.add_argument( |
109 | 111 | '-n', '--node-name', |
110 | 112 | help='Name of the created publishing node') |
| 113 | + |
| 114 | + # Use the custom completion finder |
| 115 | + argcomplete.autocomplete = YamlCompletionFinder(parser) |
| 116 | + |
111 | 117 | add_qos_arguments(parser, 'publish', 'default') |
112 | 118 | add_direct_node_arguments(parser) |
113 | 119 |
|
@@ -173,7 +179,17 @@ def publisher( |
173 | 179 | if yaml_file: |
174 | 180 | msg_reader = read_msg_from_yaml(yaml_file) |
175 | 181 | else: |
176 | | - values_dictionary = yaml.safe_load(values) |
| 182 | + try: |
| 183 | + # Handle cases where the user pastes the autocompleted bash safe string |
| 184 | + if '^J' in values: |
| 185 | + values = values.replace("'", '') |
| 186 | + values = values.replace('^J', '\n') |
| 187 | + |
| 188 | + values_dictionary = yaml.safe_load(values) |
| 189 | + |
| 190 | + except (yaml.parser.ParserError, yaml.scanner.ScannerError): |
| 191 | + return 'The passed value needs to be in YAML string or a dictionary' |
| 192 | + |
177 | 193 | if not isinstance(values_dictionary, dict): |
178 | 194 | return 'The passed value needs to be a dictionary in YAML format' |
179 | 195 |
|
|
0 commit comments