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,29 +55,41 @@ def default_flake() -> FlakeId | None:
|
|||||||
|
|
||||||
|
|
||||||
def add_common_flags(parser: argparse.ArgumentParser) -> None:
|
def add_common_flags(parser: argparse.ArgumentParser) -> None:
|
||||||
parser.add_argument(
|
def argument_exists(parser: argparse.ArgumentParser, arg: str) -> bool:
|
||||||
"--debug",
|
"""
|
||||||
help="Enable debug logging",
|
Check if an argparse argument already exists.
|
||||||
action="store_true",
|
This is needed because the aliases subcommand doesn't *really*
|
||||||
default=False,
|
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
|
||||||
|
|
||||||
parser.add_argument(
|
if not argument_exists(parser, "--debug"):
|
||||||
"--option",
|
parser.add_argument(
|
||||||
help="Nix option to set",
|
"--debug",
|
||||||
nargs=2,
|
help="Enable debug logging",
|
||||||
metavar=("name", "value"),
|
action="store_true",
|
||||||
action=AppendOptionAction,
|
default=False,
|
||||||
default=[],
|
)
|
||||||
)
|
|
||||||
|
|
||||||
parser.add_argument(
|
if not argument_exists(parser, "--option"):
|
||||||
"--flake",
|
parser.add_argument(
|
||||||
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",
|
"--option",
|
||||||
default=default_flake(),
|
help="Nix option to set",
|
||||||
metavar="PATH",
|
nargs=2,
|
||||||
type=flake_path,
|
metavar=("name", "value"),
|
||||||
)
|
action=AppendOptionAction,
|
||||||
|
default=[],
|
||||||
|
)
|
||||||
|
|
||||||
|
if not argument_exists(parser, "--flake"):
|
||||||
|
parser.add_argument(
|
||||||
|
"--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",
|
||||||
|
default=default_flake(),
|
||||||
|
metavar="PATH",
|
||||||
|
type=flake_path,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def register_common_flags(parser: argparse.ArgumentParser) -> None:
|
def register_common_flags(parser: argparse.ArgumentParser) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user