Commit 2b0b7891 authored by Thomas de Grenier de Latour's avatar Thomas de Grenier de Latour
Browse files

feat: improve boolean options from env vars (empty/"false" is not true)

parent 23d38cb5
Loading
Loading
Loading
Loading
+12 −8
Original line number Diff line number Diff line
@@ -758,6 +758,10 @@ def simple_json_to_dict(json_str: str, source: str) -> dict[str,Union[int,str]]:
        ), f"Invalid value type for key {k} in {source}, expected only strings, integers and booleans"
    return options

def trueish_env_var(env_var_name: str) -> bool:
    value = os.getenv(env_var_name)
    return bool(value) and (value.lower() not in [ "0", "false", "no" ])

def run() -> None:
    # define command parser
    parser = argparse.ArgumentParser(
@@ -804,7 +808,7 @@ def run() -> None:
    parser.add_argument(
        "--skip-visibility",
        action="store_true",
        default=os.getenv("SKIP_VISIBILITY") is not None,
        default=trueish_env_var("SKIP_VISIBILITY"),
        help="skip updating the destination group or project visibility (when it exists already)",
    )
    parser.add_argument(
@@ -832,30 +836,30 @@ def run() -> None:
    parser.add_argument(
        "--insecure",
        action="store_true",
        default=os.getenv("INSECURE") is not None,
        default=trueish_env_var("INSECURE"),
        help="skip SSL verification",
    )
    parser.add_argument(
        "--update-release",
        default=os.getenv("UPDATE_RELEASE") is not None,
        default=trueish_env_var("UPDATE_RELEASE"),
        action="store_true",
        help="force the update of the latest release",
    )
    parser.add_argument(
        "--update-avatar",
        default=os.getenv("UPDATE_AVATAR") is not None,
        default=trueish_env_var("UPDATE_AVATAR"),
        action="store_true",
        help="force update the avatar images even when they exist and look the same",
    )
    parser.add_argument(
        "--no-group-description",
        default=os.getenv("GROUP_DESCRIPTION_DISABLED") is not None,
        default=trueish_env_var("GROUP_DESCRIPTION_DISABLED"),
        action="store_true",
        help="don't synchronize group description",
    )
    parser.add_argument(
        "--no-project-description",
        default=os.getenv("PROJECT_DESCRIPTION_DISABLED") is not None,
        default=trueish_env_var("PROJECT_DESCRIPTION_DISABLED"),
        action="store_true",
        help="don't synchronize project description",
    )
@@ -881,13 +885,13 @@ def run() -> None:
    )
    parser.add_argument(
        "--dry-run",
        default=os.getenv("DRY_RUN") is not None,
        default=trueish_env_var("DRY_RUN"),
        action="store_true",
        help="dry run (don't execute any write action)",
    )
    parser.add_argument(
        "--halt-on-error",
        default=os.getenv("HALT_ON_ERROR") is not None,
        default=trueish_env_var("HALT_ON_ERROR"),
        action="store_true",
        help="halt synchronizing whenever an error occurs",
    )