Skip to content

Commit 6ae5102

Browse files
committed
Change output format to match 'mbed ls' when using recursive mode (consistency)
1 parent 6a78e09 commit 6ae5102

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

mbed/mbed.py

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2097,7 +2097,7 @@ def update(rev=None, clean=False, clean_files=False, clean_deps=False, ignore=Fa
20972097

20982098
# Synch command
20992099
@subcommand('sync',
2100-
help='Synchronize library references',
2100+
help='Synchronize library references\n\n',
21012101
description=(
21022102
"Synchronizes all library and dependency references (.lib files) in the\n"
21032103
"current program or library.\n"
@@ -2171,10 +2171,7 @@ def list_(detailed=False, prefix='', p_path=None, ignore=False):
21712171
print "%s (%s)" % (prefix + (relpath(p_path, repo.path) if p_path else repo.name), ((repo.url+('#'+str(repo.rev)[:12] if repo.rev else '') if detailed else revstr) or 'no revision'))
21722172

21732173
for i, lib in enumerate(sorted(repo.libs, key=lambda l: l.path)):
2174-
if prefix:
2175-
nprefix = prefix[:-3] + ('| ' if prefix[-3] == '|' else ' ')
2176-
else:
2177-
nprefix = ''
2174+
nprefix = (prefix[:-3] + ('| ' if prefix[-3] == '|' else ' ')) if prefix else ''
21782175
nprefix += '|- ' if i < len(repo.libs)-1 else '`- '
21792176

21802177
if lib.check_repo(ignore):
@@ -2184,34 +2181,45 @@ def list_(detailed=False, prefix='', p_path=None, ignore=False):
21842181

21852182
# Command status for cross-SCM status of repositories
21862183
@subcommand('releases',
2187-
dict(name=['-a', '--all'], dest='all_refs', action='store_true', help='Show all, e.g. release candidates, alpha, betas'),
2188-
dict(name=['-r', '--recursive'], action='store_true', help='Show releases for all libraries and sub-libraries as well'),
2189-
help='Shows release tags\n\n',
2184+
dict(name=['-a', '--all'], dest='all_refs', action='store_true', help='Show all releases, including release candidates, alphas, betas, etc'),
2185+
dict(name=['-r', '--recursive'], action='store_true', help='Show release tags for all libraries and sub-libraries as well'),
2186+
help='Show release tags',
21902187
description=(
21912188
"Show release tags for the current program or library."))
2192-
def releases_(all_refs=False, recursive=False):
2189+
def releases_(all_refs=False, recursive=False, prefix='', p_path=None):
21932190
repo = Repo.fromrepo()
21942191
tags = repo.scm.gettags()
2195-
revtags = repo.scm.gettags(repo.rev) # associated tags with current commit
2192+
revtags = repo.scm.gettags(repo.rev) if repo.rev else [] # associated tags with current commit
2193+
revstr = ('#'+repo.rev[:12]+(', tags:'+', '.join(revtags[0:2]) if len(revtags) else '')) if repo.rev else ''
2194+
regex_rels = regex_rels_all if all_refs else regex_rels_official
21962195

2197-
action("Releases in %s \"%s\"\n" % (repo.pathtype(repo.path), repo.name))
2198-
regex = regex_rels_all if all_refs else regex_rels_official
2196+
# Generate list of tags
21992197
rels = []
22002198
for tag in tags:
2201-
if re.match(regex, tag[1]):
2199+
if re.match(regex_rels, tag[1]):
22022200
rels.append(tag[1] + " %s%s" % (tag[0] if verbose else "", " <- current" if tag[1] in revtags else ""))
22032201

2202+
# print header
2203+
print "%s (%s)" % (prefix + (relpath(p_path, repo.path) if p_path else repo.name), ((repo.url+('#'+str(repo.rev)[:12] if repo.rev else '') if verbose else revstr) or 'no revision'))
2204+
2205+
# print list of tags
2206+
rprefix = (prefix[:-3] + ('| ' if prefix[-3] == '|' else ' ')) if recursive and prefix else ''
2207+
rprefix += '| ' if recursive and len(repo.libs)>1 else ' '
22042208
if len(rels):
22052209
for rel in rels:
2206-
log(rel+"\n")
2210+
print rprefix+'* '+rel
22072211
else:
2208-
log("None\n")
2209-
log("\n")
2212+
print rprefix+'No release tags detected'
22102213

22112214
if recursive:
2212-
for lib in repo.libs:
2213-
with cd(lib.path):
2214-
releases_(all_refs, recursive)
2215+
for i, lib in enumerate(sorted(repo.libs, key=lambda l: l.path)):
2216+
nprefix = (prefix[:-3] + ('| ' if prefix[-3] == '|' else ' ')) if prefix else ''
2217+
nprefix += '|- ' if i < len(repo.libs)-1 else '`- '
2218+
2219+
if lib.check_repo():
2220+
with cd(lib.path):
2221+
releases_(all_refs, recursive, nprefix, repo.path)
2222+
22152223

22162224
# Command status for cross-SCM status of repositories
22172225
@subcommand('status',

0 commit comments

Comments
 (0)