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 <sjg@chromium.org>
diff --git a/tools/patman/cmdline.py b/tools/patman/cmdline.py
index 5943aa7..18434af 100644
--- a/tools/patman/cmdline.py
+++ b/tools/patman/cmdline.py
@@ -20,6 +20,11 @@
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 @@
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 @@
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 @@
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