]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
patman: Support aliases for commands and subcommands
authorSimon Glass <sjg@chromium.org>
Sat, 10 May 2025 11:05:13 +0000 (13:05 +0200)
committerSimon Glass <sjg@chromium.org>
Tue, 27 May 2025 09:07:43 +0000 (10:07 +0100)
It is laborious to type long commands, so add some aliases to speed up
use of patman. For now, allow 'pw' for patchwork and 'st' for status.

Signed-off-by: Simon Glass <sjg@chromium.org>
tools/patman/cmdline.py

index 5943aa7e47c9c838d7e1cb5f97b5c1c013a9b81d..18434af4cb71626c2049e1cc27fcc2cab6c647fd 100644 (file)
@@ -20,6 +20,11 @@ from patman import settings
 PATMAN_DIR = pathlib.Path(__file__).parent
 HAS_TESTS = os.path.exists(PATMAN_DIR / "func_test.py")
 
+# Aliases for subcommands
+ALIASES = {
+    'status': ['st'],
+    'patchwork': ['pw'],
+    }
 
 class ErrorCatchingArgumentParser(argparse.ArgumentParser):
     def __init__(self, **kwargs):
@@ -126,7 +131,7 @@ def add_patchwork_subparser(subparsers):
         ArgumentParser: patchwork subparser
     """
     patchwork = subparsers.add_parser(
-        'patchwork',
+        'patchwork', aliases=ALIASES['patchwork'],
         help='Manage patchwork connection')
     patchwork.defaults_cmds = [
         ['set-project', 'U-Boot'],
@@ -173,7 +178,7 @@ def add_status_subparser(subparsers):
     Return:
         ArgumentParser: status subparser
     """
-    status = subparsers.add_parser('status',
+    status = subparsers.add_parser('status', aliases=ALIASES['status'],
                                    help='Check status of patches in patchwork')
     _add_show_comments(status)
     status.add_argument(
@@ -278,4 +283,13 @@ def parse_args(argv=None, config_fname=None, parsers=None):
         argv = argv[:-nargs] + ['send'] + rest
         args = parser.parse_args(argv)
 
+    # Resolve aliases
+    for full, aliases in ALIASES.items():
+        if args.cmd in aliases:
+            args.cmd = full
+        if 'subcmd' in args and args.subcmd in aliases:
+            args.subcmd = full
+    if args.cmd in ['series', 'upstream', 'patchwork'] and not args.subcmd:
+        parser.parse_args([args.cmd, '--help'])
+
     return args