Merge pull request 'pkgs/cli: Fix adding common flags for aliases' (#2411) from kenji/clan-core:kenji-cli/fix/common-flags into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/2411
This commit is contained in:
@@ -55,6 +55,16 @@ def default_flake() -> FlakeId | None:
|
|||||||
|
|
||||||
|
|
||||||
def add_common_flags(parser: argparse.ArgumentParser) -> None:
|
def add_common_flags(parser: argparse.ArgumentParser) -> None:
|
||||||
|
def argument_exists(parser: argparse.ArgumentParser, arg: str) -> bool:
|
||||||
|
"""
|
||||||
|
Check if an argparse argument already exists.
|
||||||
|
This is needed because the aliases subcommand doesn't *really*
|
||||||
|
create an alias - it duplicates the actual parser in the tree
|
||||||
|
making duplication inevitable while naively traversing.
|
||||||
|
"""
|
||||||
|
return any(arg in action.option_strings for action in parser._actions) # noqa: SLF001 -> private_member accessed
|
||||||
|
|
||||||
|
if not argument_exists(parser, "--debug"):
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--debug",
|
"--debug",
|
||||||
help="Enable debug logging",
|
help="Enable debug logging",
|
||||||
@@ -62,6 +72,7 @@ def add_common_flags(parser: argparse.ArgumentParser) -> None:
|
|||||||
default=False,
|
default=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not argument_exists(parser, "--option"):
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--option",
|
"--option",
|
||||||
help="Nix option to set",
|
help="Nix option to set",
|
||||||
@@ -71,6 +82,7 @@ def add_common_flags(parser: argparse.ArgumentParser) -> None:
|
|||||||
default=[],
|
default=[],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not argument_exists(parser, "--flake"):
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--flake",
|
"--flake",
|
||||||
help="path to the flake where the clan resides in, can be a remote flake or local, can be set through the [CLAN_DIR] environment variable",
|
help="path to the flake where the clan resides in, can be a remote flake or local, can be set through the [CLAN_DIR] environment variable",
|
||||||
|
|||||||
Reference in New Issue
Block a user