From: Simon Glass Date: Sat, 10 May 2025 11:05:13 +0000 (+0200) Subject: patman: Support aliases for commands and subcommands X-Git-Tag: v2025.10-rc1~118^2~69^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d6c3f4587889a84f38a90776edaed6e7baa71475;p=thirdparty%2Fu-boot.git patman: Support aliases for commands and subcommands 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 --- 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