nixos-rebuild-ng: show help when manpage is disabled

This commit is contained in:
Thiago Kenji Okada 2024-12-06 10:56:00 +00:00
parent da566994ea
commit bd200697e9
2 changed files with 11 additions and 5 deletions

View File

@ -47,7 +47,9 @@ python3Packages.buildPythonApplication rec {
postPatch = ''
substituteInPlace nixos_rebuild/__init__.py \
--subst-var-by executable ${executable}
--subst-var-by executable ${executable} \
--subst-var-by withShellFiles ${lib.boolToString withShellFiles}
substituteInPlace pyproject.toml \
--subst-var-by executable ${executable}
'';

View File

@ -180,6 +180,14 @@ def parse_args(
for group, parser in sub_parsers.items()
}
if args.help or args.action is None:
if "@withShellFiles@" == "true":
r = run(["man", "8", "@executable@"], check=False)
parser.exit(r.returncode)
else:
parser.print_help()
parser.exit()
def parser_warn(msg: str) -> None:
print(f"{parser.prog}: warning: {msg}", file=sys.stderr)
@ -194,10 +202,6 @@ def parse_args(
if args.ask_sudo_password:
args.sudo = True
if args.help or args.action is None:
r = run(["man", "8", "@executable@"], check=False)
parser.exit(r.returncode)
# TODO: use deprecated=True in Python >=3.13
if args.install_grub:
parser_warn("--install-grub deprecated, use --install-bootloader instead")