diff --git a/examples/common/common.py b/examples/common/common.py index 7246f39..43a8642 100644 --- a/examples/common/common.py +++ b/examples/common/common.py @@ -46,6 +46,15 @@ def add_config_arguments(parser: argparse.ArgumentParser): action="store_true", help="Disable multicast scouting.", ) + parser.add_argument( + "--cfg", + dest="cfg", + metavar="CFG", + default=[], + action="append", + type=str, + help="Allows arbitrary configuration changes as column-separated KEY:VALUE pairs. Where KEY must be a valid config path and VALUE must be a valid JSON5 string that can be deserialized to the expected type for the KEY field. Example: --cfg='transport/unicast/max_links:2'.", + ) def get_config_from_args(args) -> zenoh.Config: @@ -63,4 +72,12 @@ def get_config_from_args(args) -> zenoh.Config: if args.no_multicast_scouting: conf.insert_json5("scouting/multicast/enabled", json.dumps(False)) + for c in args.cfg: + try: + [key, value] = c.split(":") + except: + print(f"`--cfg` argument: expected KEY:VALUE pair, got {c}") + raise + conf.insert_json5(key, value) + return conf