Skip to content

Commit d316265

Browse files
committed
Update command help to add short command help for 'mbed --help' and descriptive help for 'mbed <command> -h/--help'
1 parent bc75f46 commit d316265

File tree

1 file changed

+62
-40
lines changed

1 file changed

+62
-40
lines changed

mbed/mbed.py

Lines changed: 62 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,12 +1335,17 @@ def formaturl(url, format="default"):
13351335
cwd_dest = "program" if cwd_type == "directory" else "library"
13361336

13371337
# Subparser handling
1338-
parser = argparse.ArgumentParser(description="Command-line code management tool for ARM mbed OS - http://www.mbed.com\nversion %s" % ver)
1338+
parser = argparse.ArgumentParser(prog='mbed',
1339+
description="Command-line code management tool for ARM mbed OS - http://www.mbed.com\nversion %s\n\n" % ver,
1340+
formatter_class=argparse.RawTextHelpFormatter)
13391341
subparsers = parser.add_subparsers(title="Commands", metavar=" ")
13401342

13411343
# Process handling
13421344
def subcommand(name, *args, **kwargs):
13431345
def subcommand(command):
1346+
if not kwargs.get('description') and kwargs.get('help'):
1347+
kwargs['description'] = kwargs['help']
1348+
13441349
subparser = subparsers.add_parser(name, **kwargs)
13451350

13461351
for arg in args:
@@ -1380,7 +1385,8 @@ def thunk(parsed_args):
13801385
dict(name='--create-only', action='store_true', help='Only create program, do not import mbed-os or mbed library.'),
13811386
dict(name='--depth', nargs='?', help='Number of revisions to fetch the mbed OS repository when creating new program. Default: all revisions.'),
13821387
dict(name='--protocol', nargs='?', help='Transport protocol when fetching the mbed OS repository when creating new program. Supported: https, http, ssh, git. Default: inferred from URL.'),
1383-
help='Create a new program based on the specified source control management. Will create a new library when called from inside a program. Supported SCMs: %s.' % (', '.join([s.name for s in scms.values()])))
1388+
description='Create new mbed program or library. Will create a new library when called from inside a program. Supported SCMs: %s.' % (', '.join([s.name for s in scms.values()])),
1389+
help='Create new mbed program or library')
13841390
def new(name, scm='git', program=False, library=False, mbedlib=False, create_only=False, depth=None, protocol=None):
13851391
global cwd_root
13861392

@@ -1448,7 +1454,8 @@ def new(name, scm='git', program=False, library=False, mbedlib=False, create_onl
14481454
dict(name=['-I', '--ignore'], action='store_true', help='Ignore errors related to cloning and updating.'),
14491455
dict(name='--depth', nargs='?', help='Number of revisions to fetch from the remote repository. Default: all revisions.'),
14501456
dict(name='--protocol', nargs='?', help='Transport protocol for the source control management. Supported: https, http, ssh, git. Default: inferred from URL.'),
1451-
help='Import a program and its dependencies into the current directory or specified destination path.')
1457+
description='Import a program and its dependencies into the current directory or specified destination path.',
1458+
help='Import program from URL')
14521459
def import_(url, path=None, ignore=False, depth=None, protocol=None, top=True):
14531460
global cwd_root
14541461

@@ -1501,37 +1508,15 @@ def import_(url, path=None, ignore=False, depth=None, protocol=None, top=True):
15011508
Program(repo.path).post_action()
15021509

15031510

1504-
# Deploy command
1505-
@subcommand('deploy',
1506-
dict(name=['-I', '--ignore'], action='store_true', help='Ignore errors related to cloning and updating.'),
1507-
dict(name='--depth', nargs='?', help='Number of revisions to fetch from the remote repository. Default: all revisions.'),
1508-
dict(name='--protocol', nargs='?', help='Transport protocol for the source control management. Supported: https, http, ssh, git. Default: inferred from URL.'),
1509-
help='Import missing dependencies in the current program or library.')
1510-
def deploy(ignore=False, depth=None, protocol=None, top=True):
1511-
repo = Repo.fromrepo()
1512-
repo.ignores()
1513-
1514-
for lib in repo.libs:
1515-
if os.path.isdir(lib.path):
1516-
if lib.check_repo():
1517-
with cd(lib.path):
1518-
update(lib.rev, ignore=ignore, depth=depth, protocol=protocol, top=False)
1519-
else:
1520-
import_(lib.fullurl, lib.path, ignore=ignore, depth=depth, protocol=protocol, top=False)
1521-
repo.ignore(relpath(repo.path, lib.path))
1522-
1523-
if top:
1524-
Program(repo.path).post_action()
1525-
1526-
15271511
# Add library command
15281512
@subcommand('add',
15291513
dict(name='url', help='URL of the library'),
15301514
dict(name='path', nargs='?', help='Destination name or path. Default: current folder.'),
15311515
dict(name=['-I', '--ignore'], action='store_true', help='Ignore errors related to cloning and updating.'),
15321516
dict(name='--depth', nargs='?', help='Number of revisions to fetch from the remote repository. Default: all revisions.'),
15331517
dict(name='--protocol', nargs='?', help='Transport protocol for the source control management. Supported: https, http, ssh, git. Default: inferred from URL.'),
1534-
help='Add a library and its dependencies into the current %s or specified destination path.' % cwd_type)
1518+
description='Add a library and its dependencies into the current %s or specified destination path.' % cwd_type,
1519+
help='Add library from URL')
15351520
def add(url, path=None, ignore=False, depth=None, protocol=None, top=True):
15361521
repo = Repo.fromrepo()
15371522

@@ -1550,7 +1535,8 @@ def add(url, path=None, ignore=False, depth=None, protocol=None, top=True):
15501535
# Remove library
15511536
@subcommand('remove',
15521537
dict(name='path', help='Local library name or path'),
1553-
help='Remove specified library and its dependencies from the current %s.' % cwd_type)
1538+
description='Remove specified library and its dependencies from the current %s.' % cwd_type,
1539+
help='Remove library')
15541540
def remove(path):
15551541
repo = Repo.fromrepo()
15561542
if not Repo.isrepo(path):
@@ -1563,10 +1549,35 @@ def remove(path):
15631549
repo.unignore(relpath(repo.path, lib.path))
15641550

15651551

1552+
# Deploy command
1553+
@subcommand('deploy',
1554+
dict(name=['-I', '--ignore'], action='store_true', help='Ignore errors related to cloning and updating.'),
1555+
dict(name='--depth', nargs='?', help='Number of revisions to fetch from the remote repository. Default: all revisions.'),
1556+
dict(name='--protocol', nargs='?', help='Transport protocol for the source control management. Supported: https, http, ssh, git. Default: inferred from URL.'),
1557+
description='Import missing dependencies in the current program or library.',
1558+
help='Find and add missing libraries')
1559+
def deploy(ignore=False, depth=None, protocol=None, top=True):
1560+
repo = Repo.fromrepo()
1561+
repo.ignores()
1562+
1563+
for lib in repo.libs:
1564+
if os.path.isdir(lib.path):
1565+
if lib.check_repo():
1566+
with cd(lib.path):
1567+
update(lib.rev, ignore=ignore, depth=depth, protocol=protocol, top=False)
1568+
else:
1569+
import_(lib.fullurl, lib.path, ignore=ignore, depth=depth, protocol=protocol, top=False)
1570+
repo.ignore(relpath(repo.path, lib.path))
1571+
1572+
if top:
1573+
Program(repo.path).post_action()
1574+
1575+
15661576
# Publish command
15671577
@subcommand('publish',
15681578
dict(name=['-A', '--all'], action='store_true', help='Publish all branches, including new. Default: push only the current branch.'),
1569-
help='Publish current %s and its dependencies to associated remote repository URLs.' % cwd_type)
1579+
description='Publish current %s and its dependencies to associated remote repository URLs.' % cwd_type,
1580+
help='Publish program or library')
15701581
def publish(all=None, top=True):
15711582
if top:
15721583
action("Checking for local modifications...")
@@ -1608,7 +1619,8 @@ def publish(all=None, top=True):
16081619
dict(name=['-I', '--ignore'], action='store_true', help='Ignore errors related to unpublished libraries, unpublished or uncommitted changes, and attempt to update from associated remote repository URLs.'),
16091620
dict(name='--depth', nargs='?', help='Number of revisions to fetch from the remote repository. Default: all revisions.'),
16101621
dict(name='--protocol', nargs='?', help='Transport protocol for the source control management. Supported: https, http, ssh, git. Default: inferred from URL.'),
1611-
help='Update current %s and its dependencies from associated remote repository URLs.' % cwd_type)
1622+
description='Update current %s and its dependencies from associated remote repository URLs.' % cwd_type,
1623+
help='Update to branch, tag, revision or latest')
16121624
def update(rev=None, clean=False, force=False, ignore=False, top=True, depth=None, protocol=None):
16131625
if top and clean:
16141626
sync()
@@ -1702,7 +1714,8 @@ def update(rev=None, clean=False, force=False, ignore=False, top=True, depth=Non
17021714

17031715
# Synch command
17041716
@subcommand('sync',
1705-
help='Synchronize dependency references (.lib files) in the current %s.' % cwd_type)
1717+
description='Synchronize dependency references (.lib files) in the current %s.' % cwd_type,
1718+
help='Synchronize library references')
17061719
def sync(recursive=True, keep_refs=False, top=True):
17071720
if top and recursive:
17081721
action("Synchronizing dependency references...")
@@ -1760,7 +1773,8 @@ def sync(recursive=True, keep_refs=False, top=True):
17601773
@subcommand('ls',
17611774
dict(name=['-a', '--all'], action='store_true', help='List repository URL and revision pairs'),
17621775
dict(name=['-I', '--ignore'], action='store_true', help='Ignore errors related to missing libraries.'),
1763-
help='View the current %s dependency tree.' % cwd_type)
1776+
description='View the current %s dependency tree.' % cwd_type,
1777+
help='View library tree')
17641778
def list_(all=False, prefix='', p_path=None, ignore=False):
17651779
repo = Repo.fromrepo()
17661780
print prefix + (relpath(p_path, repo.path) if p_path else repo.name), '(%s)' % ((repo.fullurl if all else repo.rev) or 'no revision')
@@ -1780,7 +1794,8 @@ def list_(all=False, prefix='', p_path=None, ignore=False):
17801794
# Command status for cross-SCM status of repositories
17811795
@subcommand('status',
17821796
dict(name=['-I', '--ignore'], action='store_true', help='Ignore errors related to missing libraries.'),
1783-
help='Show status of the current %s and its dependencies.' % cwd_type)
1797+
description='Show changes status of the current %s and its dependencies.' % cwd_type,
1798+
help='Show version control status\n\n')
17841799
def status_(ignore=False):
17851800
repo = Repo.fromrepo()
17861801
if repo.dirty():
@@ -1804,7 +1819,8 @@ def status_(ignore=False):
18041819
dict(name='--library', dest='compile_library', action='store_true', help='Compile the current %s as a static library.' % cwd_type),
18051820
dict(name='--tests', dest='compile_tests', action='store_true', help='Compile tests in TESTS directory.'),
18061821
dict(name='--test_spec', dest="test_spec", help="Destination path for a test spec file that can be used by the Greentea automated test tool. (Default is 'test_spec.json')"),
1807-
help='Compile program using the native mbed OS build system.')
1822+
description='Compile program using the native mbed OS build system.',
1823+
help='Compile program using the mbed build tools')
18081824
def compile(toolchain=None, mcu=None, source=False, build=False, clean=False, supported=False, compile_library=False, compile_tests=False, test_spec="test_spec.json"):
18091825
args = remainder
18101826
# Gather remaining arguments
@@ -1882,7 +1898,8 @@ def compile(toolchain=None, mcu=None, source=False, build=False, clean=False, su
18821898
dict(name=['-m', '--mcu'], help='Compile target. Example: K64F, NUCLEO_F401RE, NRF51822...'),
18831899
dict(name='--source', action='append', help='Source directory. Default: . (current dir)'),
18841900
dict(name='--prefix', action='append', help='Restrict listing to parameters that have this prefix'),
1885-
help='Display program\'s compile configuration.')
1901+
description='Show program\'s compile configuration.',
1902+
help='Show compile configuration.')
18861903
def config(toolchain=None, mcu=None, source=False, prefix=None):
18871904
# Find the root of the program
18881905
program = Program(os.getcwd(), True)
@@ -1923,7 +1940,8 @@ def config(toolchain=None, mcu=None, source=False, prefix=None):
19231940
# Test command
19241941
@subcommand('test',
19251942
dict(name=['-l', '--list'], dest='tlist', action='store_true', help='List all of the available tests'),
1926-
help='Find and build tests in a program and its libraries.')
1943+
description='Find and build tests in a program and its libraries.',
1944+
help='Find and build tests')
19271945
def test(tlist=False):
19281946
# Gather remaining arguments
19291947
args = remainder
@@ -1948,7 +1966,8 @@ def test(tlist=False):
19481966
@subcommand('export',
19491967
dict(name=['-i', '--ide'], help='IDE to create project files for. Example: UVISION,DS5,IAR', required=True),
19501968
dict(name=['-m', '--mcu'], help='Export for target MCU. Example: K64F, NUCLEO_F401RE, NRF51822...'),
1951-
help='Generate project files for desktop IDEs for the current program.')
1969+
description='Generate project files for desktop IDEs for the current program.',
1970+
help='Generate IDE project')
19521971
def export(ide=None, mcu=None):
19531972
# Gather remaining arguments
19541973
args = remainder
@@ -1971,7 +1990,8 @@ def export(ide=None, mcu=None):
19711990

19721991
# Test command
19731992
@subcommand('detect',
1974-
help='Detect mbed targets/boards connected to this system.')
1993+
description='Detect mbed targets/boards connected to this system.',
1994+
help='Detect connected mbed targets/boards\n\n')
19751995
def detect():
19761996
# Gather remaining arguments
19771997
args = remainder
@@ -2007,7 +2027,8 @@ def toolchain_(name=None):
20072027
dict(name='name', help='Variable name. E.g. "target", "toolchain", "protocol"'),
20082028
dict(name='value', nargs='?', help='Value. Will show the currently set default value for a variable if not specified.'),
20092029
dict(name=['-u', '--unset'], dest='unset', action='store_true', help='Unset the specified variable.'),
2010-
help='Set or get program default options.')
2030+
description='Set or get program default options.',
2031+
help='Program options')
20112032
def default_(name, value=None, unset=False):
20122033
# Find the root of the program
20132034
program = Program(os.getcwd())
@@ -2029,7 +2050,8 @@ def default_(name, value=None, unset=False):
20292050
dict(name='name', help='Variable name. E.g. "target", "toolchain", "protocol"'),
20302051
dict(name='value', nargs='?', help='Value. Will show the currently set default value for a variable if not specified.'),
20312052
dict(name=['-u', '--unset'], dest='unset', action='store_true', help='Unset the specified variable.'),
2032-
help='Set or get global options for all programs. Global options may be overridden by program defaults.')
2053+
description='Set or get global options for all programs. Global options may be overridden by program defaults.',
2054+
help='Global options')
20332055
def default_(name, value=None, unset=False):
20342056
g = Global()
20352057
var = str(name).upper()

0 commit comments

Comments
 (0)