Skip to content

Commit dd543b7

Browse files
authored
Merge pull request #591 from screamerbg/feature_short_cmds
UX: Shortened commands/aliases for various commands
2 parents eb84eb9 + 21574af commit dd543b7

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

mbed/mbed.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,10 +1673,14 @@ def formaturl(url, format="default"):
16731673
# Process handling
16741674
def subcommand(name, *args, **kwargs):
16751675
def __subcommand(command):
1676+
aliases = []
16761677
if not kwargs.get('description') and kwargs.get('help'):
16771678
kwargs['description'] = kwargs['help']
16781679
if not kwargs.get('formatter_class'):
16791680
kwargs['formatter_class'] = argparse.RawDescriptionHelpFormatter
1681+
if kwargs.get('hidden_aliases'):
1682+
aliases = kwargs.get('hidden_aliases')
1683+
del kwargs['hidden_aliases']
16801684

16811685
subparser = subparsers.add_parser(name, **kwargs)
16821686
subcommands[name] = subparser
@@ -1704,6 +1708,11 @@ def thunk(parsed_args):
17041708
return command(**argv)
17051709

17061710
subparser.set_defaults(command=thunk)
1711+
1712+
# set hidden aliases if any
1713+
for alias in aliases:
1714+
subparsers._name_parser_map[alias] = subparsers._name_parser_map[name]
1715+
17071716
return command
17081717
return __subcommand
17091718

@@ -1800,6 +1809,7 @@ def new(name, scm='git', program=False, library=False, mbedlib=False, create_onl
18001809
dict(name=['-I', '--ignore'], action='store_true', help='Ignore errors related to cloning and updating.'),
18011810
dict(name='--depth', nargs='?', help='Number of revisions to fetch from the remote repository. Default: all revisions.'),
18021811
dict(name='--protocol', nargs='?', help='Transport protocol for the source control management. Supported: https, http, ssh, git. Default: inferred from URL.'),
1812+
hidden_aliases=['im', 'imp'],
18031813
help='Import program from URL',
18041814
description=(
18051815
"Imports mbed program and its dependencies from a source control based URL\n"
@@ -1870,6 +1880,7 @@ def import_(url, path=None, ignore=False, depth=None, protocol=None, top=True):
18701880
dict(name=['-I', '--ignore'], action='store_true', help='Ignore errors related to cloning and updating.'),
18711881
dict(name='--depth', nargs='?', help='Number of revisions to fetch from the remote repository. Default: all revisions.'),
18721882
dict(name='--protocol', nargs='?', help='Transport protocol for the source control management. Supported: https, http, ssh, git. Default: inferred from URL.'),
1883+
hidden_aliases=['ad'],
18731884
help='Add library from URL',
18741885
description=(
18751886
"Adds mbed library and its dependencies from a source control based URL\n"
@@ -1894,6 +1905,7 @@ def add(url, path=None, ignore=False, depth=None, protocol=None, top=True):
18941905
@subcommand('remove',
18951906
dict(name='path', help='Local library name or path'),
18961907
help='Remove library',
1908+
hidden_aliases=['rm', 'rem'],
18971909
description=(
18981910
"Remove specified library, its dependencies and references from the current\n"
18991911
"You can re-add the library from its URL via 'mbed add <library URL>'."))
@@ -1942,6 +1954,7 @@ def deploy(ignore=False, depth=None, protocol=None, top=True):
19421954
@subcommand('publish',
19431955
dict(name=['-A', '--all'], dest='all_refs', action='store_true', help='Publish all branches, including new ones. Default: push only the current branch.'),
19441956
dict(name=['-M', '--message'], dest='msg', type=str, nargs='?', help='Commit message. Default: prompts for commit message.'),
1957+
hidden_aliases=['pub'],
19451958
help='Publish program or library',
19461959
description=(
19471960
"Publishes the current program or library and all dependencies to their\nassociated remote repository URLs.\n"
@@ -1998,6 +2011,7 @@ def publish(all_refs=None, msg=None, top=True):
19982011
dict(name='--depth', nargs='?', help='Number of revisions to fetch from the remote repository. Default: all revisions.'),
19992012
dict(name='--protocol', nargs='?', help='Transport protocol for the source control management. Supported: https, http, ssh, git. Default: inferred from URL.'),
20002013
dict(name=['-l', '--latest-deps'], action='store_true', help='Update all dependencies to the latest revision of their current branch. WARNING: Ignores lib files'),
2014+
hidden_aliases=['up'],
20012015
help='Update to branch, tag, revision or latest',
20022016
description=(
20032017
"Updates the current program or library and its dependencies to specified\nbranch, tag or revision.\n"
@@ -2196,6 +2210,7 @@ def list_(detailed=False, prefix='', p_path=None, ignore=False):
21962210
dict(name=['-a', '--all'], dest='detailed', action='store_true', help='Show revision hashes'),
21972211
dict(name=['-u', '--unstable'], dest='unstable', action='store_true', help='Show unstable releases well, e.g. release candidates, alphas, betas, etc'),
21982212
dict(name=['-r', '--recursive'], action='store_true', help='Show release tags for all libraries and sub-libraries as well'),
2213+
hidden_aliases=['rel', 'rels'],
21992214
help='Show release tags',
22002215
description=(
22012216
"Show release tags for the current program or library."))
@@ -2237,6 +2252,7 @@ def releases_(detailed=False, unstable=False, recursive=False, prefix='', p_path
22372252
# Command status for cross-SCM status of repositories
22382253
@subcommand('status',
22392254
dict(name=['-I', '--ignore'], action='store_true', help='Ignore errors related to missing libraries.'),
2255+
hidden_aliases=['st', 'stat'],
22402256
help='Show version control status\n\n',
22412257
description=(
22422258
"Show uncommitted changes a program or library and its dependencies."))
@@ -2531,6 +2547,7 @@ def export(ide=None, target=None, source=False, clean=False, supported=False, ap
25312547

25322548
# Test command
25332549
@subcommand('detect',
2550+
hidden_aliases=['det'],
25342551
help='Detect connected mbed targets/boards\n\n',
25352552
description=(
25362553
"Detects mbed targets/boards connected to this system and shows supported\n"
@@ -2581,6 +2598,7 @@ def detect():
25812598
dict(name=['-G', '--global'], dest='global_cfg', action='store_true', help='Use global settings, not local'),
25822599
dict(name=['-U', '--unset'], dest='unset', action='store_true', help='Unset the specified variable.'),
25832600
dict(name=['-L', '--list'], dest='list_config', action='store_true', help='List mbed tool configuration. Not to be confused with compile configuration, e.g. "mbed compile --config".'),
2601+
hidden_aliases=['cfg', 'conf'],
25842602
help='Tool configuration',
25852603
description=(
25862604
"Gets, sets or unsets mbed tool configuration options.\n"

0 commit comments

Comments
 (0)