@@ -1386,11 +1386,6 @@ def formaturl(url, format="default"):
1386
1386
return url
1387
1387
1388
1388
1389
- # Help messages adapt based on current dir
1390
- cwd_root = os .getcwd ()
1391
- cwd_type = Repo .pathtype (cwd_root )
1392
- cwd_dest = "program" if cwd_type == "directory" else "library"
1393
-
1394
1389
# Subparser handling
1395
1390
parser = argparse .ArgumentParser (prog = 'mbed' ,
1396
1391
description = "Command-line code management tool for ARM mbed OS - http://www.mbed.com\n version %s\n \n Use 'mbed <command> -h|--help' for detailed help.\n Online manual and guide available at https://github.com/ARMmbed/mbed-cli" % ver ,
@@ -1522,8 +1517,8 @@ def new(name, scm='git', program=False, library=False, mbedlib=False, create_onl
1522
1517
1523
1518
# Import command
1524
1519
@subcommand ('import' ,
1525
- dict (name = 'url' , help = 'URL of the %s' % cwd_dest ),
1526
- dict (name = 'path' , nargs = '?' , help = 'Destination name or path. Default: current %s.' % cwd_type ),
1520
+ dict (name = 'url' , help = 'URL of the program' ),
1521
+ dict (name = 'path' , nargs = '?' , help = 'Destination name or path. Default: current directory.' ),
1527
1522
dict (name = ['-I' , '--ignore' ], action = 'store_true' , help = 'Ignore errors related to cloning and updating.' ),
1528
1523
dict (name = '--depth' , nargs = '?' , help = 'Number of revisions to fetch from the remote repository. Default: all revisions.' ),
1529
1524
dict (name = '--protocol' , nargs = '?' , help = 'Transport protocol for the source control management. Supported: https, http, ssh, git. Default: inferred from URL.' ),
@@ -1664,11 +1659,11 @@ def deploy(ignore=False, depth=None, protocol=None, top=True):
1664
1659
dict (name = ['-M' , '--message' ], dest = 'msg' , type = str , nargs = '?' , help = 'Commit message. Default: prompts for commit message.' ),
1665
1660
help = 'Publish program or library' ,
1666
1661
description = (
1667
- "Publishes this %s and all dependencies to their associated remote\n repository URLs.\n "
1662
+ "Publishes the current program or library and all dependencies to their\n associated remote repository URLs.\n "
1668
1663
"This command performs various consistency checks for local uncommitted changes\n "
1669
1664
"and unpublished revisions and encourages to commit/push them.\n "
1670
1665
"Online guide about collaboration is available at:\n "
1671
- "www.mbed.com/collab_guide" % cwd_type ))
1666
+ "www.mbed.com/collab_guide" ))
1672
1667
def publish (all_refs = None , msg = None , top = True ):
1673
1668
if top :
1674
1669
action ("Checking for local modifications..." )
@@ -1716,13 +1711,16 @@ def publish(all_refs=None, msg=None, top=True):
1716
1711
dict (name = '--protocol' , nargs = '?' , help = 'Transport protocol for the source control management. Supported: https, http, ssh, git. Default: inferred from URL.' ),
1717
1712
help = 'Update to branch, tag, revision or latest' ,
1718
1713
description = (
1719
- "Updates this %s and its dependencies to specified branch , tag or revision.\n "
1714
+ "Updates the current program or library and its dependencies to specified\n branch , tag or revision.\n "
1720
1715
"Alternatively fetches from associated remote repository URL and updates to the\n "
1721
- "latest revision in the current branch." % cwd_type ))
1716
+ "latest revision in the current branch." ))
1722
1717
def update (rev = None , clean = False , clean_files = False , clean_deps = False , ignore = False , top = True , depth = None , protocol = None ):
1723
1718
if top and clean :
1724
1719
sync ()
1725
1720
1721
+ cwd_type = Repo .pathtype (cwd_root )
1722
+ cwd_dest = "program" if cwd_type == "directory" else "library"
1723
+
1726
1724
repo = Repo .fromrepo ()
1727
1725
# A copy of repo containing the .lib layout before updating
1728
1726
repo_orig = Repo .fromrepo ()
@@ -1818,8 +1816,8 @@ def update(rev=None, clean=False, clean_files=False, clean_deps=False, ignore=Fa
1818
1816
help = 'Synchronize library references' ,
1819
1817
description = (
1820
1818
"Synchronizes all library and dependency references (.lib files) in the\n "
1821
- "current %s .\n "
1822
- "Note that this will remove all invalid library references." % cwd_type ))
1819
+ "current program or library .\n "
1820
+ "Note that this will remove all invalid library references." ))
1823
1821
def sync (recursive = True , keep_refs = False , top = True ):
1824
1822
if top and recursive :
1825
1823
action ("Synchronizing dependency references..." )
@@ -1868,6 +1866,7 @@ def sync(recursive=True, keep_refs=False, top=True):
1868
1866
sync (keep_refs = keep_refs , top = False )
1869
1867
1870
1868
# Update the .lib reference in the parent repository
1869
+ cwd_type = Repo .pathtype (cwd_root )
1871
1870
if top and cwd_type == "library" :
1872
1871
repo = Repo .fromrepo ()
1873
1872
repo .write ()
@@ -1879,7 +1878,7 @@ def sync(recursive=True, keep_refs=False, top=True):
1879
1878
dict (name = ['-I' , '--ignore' ], action = 'store_true' , help = 'Ignore errors related to missing libraries.' ),
1880
1879
help = 'View dependency tree' ,
1881
1880
description = (
1882
- "View the dependency tree in this %s." % cwd_type ))
1881
+ "View the dependency tree of the current program or library." ))
1883
1882
def list_ (detailed = False , prefix = '' , p_path = None , ignore = False ):
1884
1883
repo = Repo .fromrepo ()
1885
1884
print prefix + (relpath (p_path , repo .path ) if p_path else repo .name ), '(%s)' % ((repo .url + ('#' + str (repo .rev )[:12 ] if repo .rev else '' ) if detailed else str (repo .rev )[:12 ]) or 'no revision' )
@@ -1901,7 +1900,7 @@ def list_(detailed=False, prefix='', p_path=None, ignore=False):
1901
1900
dict (name = ['-I' , '--ignore' ], action = 'store_true' , help = 'Ignore errors related to missing libraries.' ),
1902
1901
help = 'Show version control status\n \n ' ,
1903
1902
description = (
1904
- "Show uncommitted changes in this %s and its dependencies." % cwd_type ))
1903
+ "Show uncommitted changes a program or library and its dependencies." ))
1905
1904
def status_ (ignore = False ):
1906
1905
repo = Repo .fromrepo ()
1907
1906
if repo .dirty ():
@@ -1918,7 +1917,7 @@ def status_(ignore=False):
1918
1917
@subcommand ('compile' ,
1919
1918
dict (name = ['-t' , '--toolchain' ], help = 'Compile toolchain. Example: ARM, uARM, GCC_ARM, IAR' ),
1920
1919
dict (name = ['-m' , '--mcu' ], help = 'Compile target. Example: K64F, NUCLEO_F401RE, NRF51822...' ),
1921
- dict (name = '--library' , dest = 'compile_library' , action = 'store_true' , help = 'Compile the current %s as a static library.' % cwd_type ),
1920
+ dict (name = '--library' , dest = 'compile_library' , action = 'store_true' , help = 'Compile the current program or library as a static library.' ),
1922
1921
dict (name = '--config' , dest = 'compile_config' , action = 'store_true' , help = 'Show run-time compile configuration' ),
1923
1922
dict (name = '--prefix' , dest = 'config_prefix' , action = 'append' , help = 'Restrict listing to parameters that have this prefix' ),
1924
1923
dict (name = '--source' , action = 'append' , help = 'Source directory. Default: . (current dir)' ),
@@ -2229,39 +2228,44 @@ def toolchain_(name=None, global_cfg=False, supported=False):
2229
2228
def help_ ():
2230
2229
return parser .print_help ()
2231
2230
2232
- # Parse/run command
2233
- if len ( sys . argv ) <= 1 :
2234
- help_ ()
2235
- sys . exit ( 1 )
2236
-
2237
- if '--version' in sys . argv :
2238
- print ver
2239
- sys . exit ( 0 )
2240
-
2241
- pargs , remainder = parser . parse_known_args ()
2242
- status = 1
2243
-
2244
- try :
2245
- very_verbose = pargs . very_verbose
2246
- verbose = very_verbose or pargs . verbose
2247
- log ( 'Working path \" %s \" (%s)' % ( os . getcwd (), cwd_type ))
2248
- status = pargs . command ( pargs )
2249
- except ProcessException as e :
2250
- error (
2251
- " \" %s \" returned error code %d. \n "
2252
- "Command \" %s\" in \" %s \" " % (e [ 1 ], e [ 0 ], e [ 2 ], e [ 3 ] ), e [ 0 ] )
2253
- except OSError as e :
2254
- if e [ 0 ] == errno . ENOENT :
2231
+ # Help messages adapt based on current dir
2232
+ cwd_root = os . getcwd ()
2233
+
2234
+
2235
+ if __name__ == "__main__" :
2236
+ # Parse/run command
2237
+ if len ( sys . argv ) <= 1 :
2238
+ help_ ( )
2239
+ sys . exit ( 1 )
2240
+
2241
+ if '--version' in sys . argv :
2242
+ print ver
2243
+ sys . exit ( 0 )
2244
+
2245
+ pargs , remainder = parser . parse_known_args ()
2246
+ status = 1
2247
+
2248
+ try :
2249
+ very_verbose = pargs . very_verbose
2250
+ verbose = very_verbose or pargs . verbose
2251
+ log ( 'Working path \" %s\" (%s)' % (os . getcwd ( ), Repo . pathtype ( cwd_root )) )
2252
+ status = pargs . command ( pargs )
2253
+ except ProcessException as e :
2255
2254
error (
2256
- "Could not detect one of the command-line tools.\n "
2257
- "You could retry the last command with \" -v\" flag for verbose output\n " , e [0 ])
2258
- else :
2259
- error ('OS Error: %s' % e [1 ], e [0 ])
2260
- except KeyboardInterrupt as e :
2261
- log ('User aborted!' , - 1 )
2262
- sys .exit (255 )
2263
- except Exception as e :
2264
- if very_verbose :
2265
- traceback .print_exc (file = sys .stdout )
2266
- error ("Unknown Error: %s" % e , 255 )
2267
- sys .exit (status or 0 )
2255
+ "\" %s\" returned error code %d.\n "
2256
+ "Command \" %s\" in \" %s\" " % (e [1 ], e [0 ], e [2 ], e [3 ]), e [0 ])
2257
+ except OSError as e :
2258
+ if e [0 ] == errno .ENOENT :
2259
+ error (
2260
+ "Could not detect one of the command-line tools.\n "
2261
+ "You could retry the last command with \" -v\" flag for verbose output\n " , e [0 ])
2262
+ else :
2263
+ error ('OS Error: %s' % e [1 ], e [0 ])
2264
+ except KeyboardInterrupt as e :
2265
+ log ('User aborted!' , - 1 )
2266
+ sys .exit (255 )
2267
+ except Exception as e :
2268
+ if very_verbose :
2269
+ traceback .print_exc (file = sys .stdout )
2270
+ error ("Unknown Error: %s" % e , 255 )
2271
+ sys .exit (status or 0 )
0 commit comments