[PATCH 20/25] patman: Support aliases for commands and subcommands

Simon Glass sjg at chromium.org
Sat May 10 13:05:13 CEST 2025


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 at chromium.org>
---

 tools/patman/cmdline.py | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/tools/patman/cmdline.py b/tools/patman/cmdline.py
index 5943aa7e47c..18434af4cb7 100644
--- a/tools/patman/cmdline.py
+++ b/tools/patman/cmdline.py
@@ -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
-- 
2.43.0



More information about the U-Boot mailing list