From 0f1c8ab4be469000cdf0438fdda64b89d0ca441d Mon Sep 17 00:00:00 2001 From: Kenneth Seet <120318851+itstrueitstrueitsrealitsreal@users.noreply.github.com> Date: Thu, 11 Jul 2024 09:43:58 +0800 Subject: [PATCH] Update user permission check for --help (#2568) * Update user permission check for --help * Fix code style * Fix code style * Fix docstring * Fix newline * Fix newline * Fix argument error * Fix formatting --- archinstall/__init__.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/archinstall/__init__.py b/archinstall/__init__.py index 5429b5cd..0f488d5d 100644 --- a/archinstall/__init__.py +++ b/archinstall/__init__.py @@ -60,10 +60,6 @@ debug(f"Graphics devices detected: {SysInfo._graphics_devices().keys()}") # For support reasons, we'll log the disk layout pre installation to match against post-installation layout debug(f"Disk states before installing: {disk.disk_layouts()}") -if 'sphinx' not in sys.modules and os.getuid() != 0: - print(_("Archinstall requires root privileges to run. See --help for more.")) - exit(1) - parser = ArgumentParser() @@ -96,6 +92,16 @@ def define_arguments(): help="Skip the version check when running archinstall") +if 'sphinx' not in sys.modules: + if '--help' in sys.argv or '-h' in sys.argv: + define_arguments() + parser.print_help() + exit(0) + if os.getuid() != 0: + print(_("Archinstall requires root privileges to run. See --help for more.")) + exit(1) + + def parse_unspecified_argument_list(unknowns: list, multiple: bool = False, err: bool = False) -> dict: """We accept arguments not defined to the parser. (arguments "ad hoc"). Internally argparse return to us a list of words so we have to parse its contents, manually.