From bbfae98adc7a710f5365a5eb25414920d21ef490 Mon Sep 17 00:00:00 2001 From: Lubomir Dolezal <lubomir.bucek@eox.at> Date: Fri, 26 Aug 2022 11:19:41 +0200 Subject: [PATCH] fix: regression caused by setting replace as a boolean flag now possible to override --- registrar/cli.py | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/registrar/cli.py b/registrar/cli.py index 645ec9a..12fbaa6 100644 --- a/registrar/cli.py +++ b/registrar/cli.py @@ -91,9 +91,18 @@ def cli( @cli.command(help="Run the registrar daemon, attaching to a Redis queue") -@click.option("--replace/--no-replace", default=None) +@click.option( + "--replace", + default=None, + help="Override config 'replace' of all routes to 'True'", +) +@click.option( + "--no-replace", + default=None, + help="Override config 'replace' of all routes to 'False'", +) @click.pass_context -def daemon(ctx, replace=False): +def daemon(ctx, replace, no_replace): """ Run the registrar daemon to listen on the given queues and execute the (de-)registrations commands. @@ -111,9 +120,13 @@ def daemon(ctx, replace=False): config: RegistrarConfig = ctx.obj["CONFIG"] - if replace is not None: + # allow to override config values from CLI + if replace: for route in config.routes.values(): - route.replace = replace + route.replace = True + elif no_replace: + for route in config.routes.values(): + route.replace = False run_daemon(config) @@ -121,9 +134,18 @@ def daemon(ctx, replace=False): @cli.command(help="Run a single, one-off registration") @click.argument("route_name", type=str) @click.argument("item", type=str) -@click.option("--replace/--no-replace", is_flag=True) +@click.option( + "--replace", + default=None, + help="Override config 'replace' of route to 'True'", +) +@click.option( + "--no-replace", + default=None, + help="Override config 'replace' of route to 'False'", +) @click.pass_context -def register(ctx, route_name, item, replace): +def register(ctx, route_name, item, replace, no_replace): """ Registers a single item. Examples: @@ -137,9 +159,11 @@ def register(ctx, route_name, item, replace): register --replace myroute "{...}" """ config: RegistrarConfig = ctx.obj["CONFIG"] - if replace is not None: - for route in config.routes.values(): - route.replace = replace + # allow to override config values from CLI + if replace: + config.routes[route_name].replace = True + elif no_replace: + config.routes[route_name].replace = False registrar.register(config.routes[route_name], config.sources, item) -- GitLab