Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/commands.py @ 1052:d8279ca39dc7
Adjust display and alignment of command options to match global options.
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 26 Aug 2005 09:56:33 +0200 |
parents | 3c918b7ad8da |
children | 1539ca091d86 |
comparison
equal
deleted
inserted
replaced
1051:3c918b7ad8da | 1052:d8279ca39dc7 |
---|---|
269 "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" | 269 "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" |
270 ) | 270 ) |
271 | 271 |
272 def help_(ui, cmd=None, with_version=False): | 272 def help_(ui, cmd=None, with_version=False): |
273 """show help for a given command or all commands""" | 273 """show help for a given command or all commands""" |
274 option_lists = [] | |
274 if cmd and cmd != 'shortlist': | 275 if cmd and cmd != 'shortlist': |
275 if with_version: | 276 if with_version: |
276 show_version(ui) | 277 show_version(ui) |
277 ui.write('\n') | 278 ui.write('\n') |
278 key, i = find(cmd) | 279 key, i = find(cmd) |
283 doc = i[0].__doc__ | 284 doc = i[0].__doc__ |
284 if ui.quiet: | 285 if ui.quiet: |
285 doc = doc.splitlines(0)[0] | 286 doc = doc.splitlines(0)[0] |
286 ui.write("%s\n" % doc.rstrip()) | 287 ui.write("%s\n" % doc.rstrip()) |
287 | 288 |
288 # aliases | |
289 if not ui.quiet: | 289 if not ui.quiet: |
290 # aliases | |
290 aliases = ', '.join(key.split('|')[1:]) | 291 aliases = ', '.join(key.split('|')[1:]) |
291 if aliases: | 292 if aliases: |
292 ui.write("\naliases: %s\n" % aliases) | 293 ui.write("\naliases: %s\n" % aliases) |
293 | 294 |
294 # options | 295 # options |
295 if not ui.quiet and i[1]: | 296 if i[1]: |
296 ui.write("\noptions:\n\n") | 297 option_lists.append(("options", i[1])) |
297 for s, l, d, c in i[1]: | |
298 opt = ' ' | |
299 if s: | |
300 opt = opt + '-' + s + ' ' | |
301 if l: | |
302 opt = opt + '--' + l + ' ' | |
303 if d: | |
304 opt = opt + '(' + str(d) + ')' | |
305 ui.write(opt, "\n") | |
306 if c: | |
307 ui.write(' %s\n' % c) | |
308 | 298 |
309 else: | 299 else: |
310 # program name | 300 # program name |
311 if ui.verbose or with_version: | 301 if ui.verbose or with_version: |
312 show_version(ui) | 302 show_version(ui) |
349 else: | 339 else: |
350 ui.write(' %-*s %s\n' % (m, f, h[f])) | 340 ui.write(' %-*s %s\n' % (m, f, h[f])) |
351 | 341 |
352 # global options | 342 # global options |
353 if ui.verbose: | 343 if ui.verbose: |
354 ui.write("\nglobal options:\n\n") | 344 option_lists.append(("global options", globalopts)) |
355 opts, descriptions = [], [] | 345 |
356 for shortopt, longopt, default, desc in globalopts: | 346 # list all option lists |
357 opts.append("%2s%s" % | 347 opt_output = [] |
358 (shortopt and "-%s" % shortopt, | 348 for title, options in option_lists: |
359 longopt and " --%s" % longopt)) | 349 opt_output.append(("\n%s:\n" % title, None)) |
360 descriptions.append(desc) | 350 for shortopt, longopt, default, desc in options: |
361 opts_len = max(map(len, opts)) | 351 opt_output.append(("%2s%s" % (shortopt and "-%s" % shortopt, |
362 for opt, desc in zip(opts, descriptions): | 352 longopt and " --%s" % longopt), |
363 ui.write(" %-*s %s\n" % (opts_len, opt, desc)) | 353 "%s%s" % (desc, |
354 default and " (default: %s)" % default | |
355 or ""))) | |
356 | |
357 if opt_output: | |
358 opts_len = max([len(line[0]) for line in opt_output if line[1]]) | |
359 for first, second in opt_output: | |
360 if second: | |
361 ui.write(" %-*s %s\n" % (opts_len, first, second)) | |
362 else: | |
363 ui.write("%s\n" % first) | |
364 | 364 |
365 # Commands start here, listed alphabetically | 365 # Commands start here, listed alphabetically |
366 | 366 |
367 def add(ui, repo, *pats, **opts): | 367 def add(ui, repo, *pats, **opts): |
368 '''add the specified files on the next commit''' | 368 '''add the specified files on the next commit''' |