Skip to content

Commit

Permalink
add --cfg arg to examples
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisBiryukov91 committed Dec 11, 2024
1 parent 7773102 commit 192f973
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions examples/common/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

0 comments on commit 192f973

Please sign in to comment.