From 51faf83696dec9de717f72534b2612ddfd752d4a Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Mon, 13 Nov 2023 10:17:54 +0100 Subject: ukify: print a more readable synopsis in --help MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/ukify') diff --git a/src/ukify/ukify.py b/src/ukify/ukify.py index b09fb4d5cc..8006624f0a 100755 --- a/src/ukify/ukify.py +++ b/src/ukify/ukify.py @@ -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, ) -- cgit v1.2.3