]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
ukify: print a more readable synopsis in --help
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 13 Nov 2023 09:17:54 +0000 (10:17 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 13 Nov 2023 09:59:30 +0000 (10:59 +0100)
The details of formatting are copied from mkosi. This results in the following:

   usage:
     ukify build [--linux=LINUX] [--initrd=INITRD] [options…]
     ukify genkey [options…]
     ukify inspect FILE… [options…]

  Build and sign Unified Kernel Images

  options:
    --version             show program's version number and exit
    ...

I put "[options…]" at the end, because that's what one would generally do
with long options like "--cmdline" and others.

src/ukify/ukify.py

index b09fb4d5cc8cd667992f261e43b8eae1671ecb5d..8006624f0a15e18631ea6dd83d3d1d3952636336 100755 (executable)
@@ -70,6 +70,14 @@ EFI_ARCHES: list[str] = sum(EFI_ARCH_MAP.values(), [])
 DEFAULT_CONFIG_DIRS = ['/run/systemd', '/etc/systemd', '/usr/local/lib/systemd', '/usr/lib/systemd']
 DEFAULT_CONFIG_FILE = 'ukify.conf'
 
+class Style:
+    bold = "\033[0;1;39m" if sys.stderr.isatty() else ""
+    gray = "\033[0;38;5;245m" if sys.stderr.isatty() else ""
+    red = "\033[31;1m" if sys.stderr.isatty() else ""
+    yellow = "\033[33;1m" if sys.stderr.isatty() else ""
+    reset = "\033[0m" if sys.stderr.isatty() else ""
+
+
 def guess_efi_arch():
     arch = os.uname().machine
 
@@ -1161,7 +1169,7 @@ CONFIG_ITEMS = [
         'positional',
         metavar = 'VERB',
         nargs = '*',
-        help = f"operation to perform ({','.join(VERBS)})",
+        help = argparse.SUPPRESS,
     ),
 
     ConfigItem(
@@ -1499,11 +1507,13 @@ class PagerHelpAction(argparse._HelpAction):  # pylint: disable=protected-access
 def create_parser():
     p = argparse.ArgumentParser(
         description='Build and sign Unified Kernel Images',
+        usage='\n  ' + textwrap.dedent('''\
+          ukify {b}build{e} [--linux=LINUX] [--initrd=INITRD] [options…]
+            ukify {b}genkey{e} [options…]
+            ukify {b}inspect{e} FILE… [options…]
+        ''').format(b=Style.bold, e=Style.reset),
         allow_abbrev=False,
         add_help=False,
-        usage='''\
-ukify [options…] VERB
-''',
         epilog='\n  '.join(('config file:', *config_example())),
         formatter_class=argparse.RawDescriptionHelpFormatter,
     )