comparison mercurial/commands.py @ 849:8933ef744325

Further help improvements: Show command aliases in 'hg help something', unless in quiet mode. Show short command description with 'hg help -q something'. Show global options in verbose mode of command help. State that Mercurial is a Distributed SCM.
author Thomas Arendsen Hein <thomas@intevation.de>
date Sat, 06 Aug 2005 15:43:12 +0100
parents 221628fe9b62
children 1df0983eb589
comparison
equal deleted inserted replaced
848:221628fe9b62 849:8933ef744325
274 ui.status("summary: %s\n" % description.splitlines()[0]) 274 ui.status("summary: %s\n" % description.splitlines()[0])
275 ui.status("\n") 275 ui.status("\n")
276 276
277 def show_version(ui): 277 def show_version(ui):
278 """output version and copyright information""" 278 """output version and copyright information"""
279 ui.write("Mercurial version %s\n" % version.get_version()) 279 ui.write("Mercurial Distributed SCM (version %s)\n"
280 % version.get_version())
280 ui.status( 281 ui.status(
281 "\nCopyright (C) 2005 Matt Mackall <mpm@selenic.com>\n" 282 "\nCopyright (C) 2005 Matt Mackall <mpm@selenic.com>\n"
282 "This is free software; see the source for copying conditions. " 283 "This is free software; see the source for copying conditions. "
283 "There is NO\nwarranty; " 284 "There is NO\nwarranty; "
284 "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" 285 "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
285 ) 286 )
286 287
287 def help_(ui, cmd=None): 288 def help_(ui, cmd=None):
288 """show help for a given command or all commands""" 289 """show help for a given command or all commands"""
289 if cmd and cmd != 'shortlist': 290 if cmd and cmd != 'shortlist':
290 i = find(cmd) 291 key, i = find(cmd)
292 # synopsis
291 ui.write("%s\n\n" % i[2]) 293 ui.write("%s\n\n" % i[2])
292 294
293 if i[1]: 295 # description
296 doc = i[0].__doc__
297 if ui.quiet:
298 doc = doc.splitlines(0)[0]
299 ui.write("%s\n" % doc.rstrip())
300
301 # aliases
302 if not ui.quiet:
303 aliases = ', '.join(key.split('|')[1:])
304 if aliases:
305 ui.write("\naliases: %s\n" % aliases)
306
307 # options
308 if not ui.quiet and i[1]:
309 ui.write("\noptions:\n\n")
294 for s, l, d, c in i[1]: 310 for s, l, d, c in i[1]:
295 opt = ' ' 311 opt = ' '
296 if s: 312 if s:
297 opt = opt + '-' + s + ' ' 313 opt = opt + '-' + s + ' '
298 if l: 314 if l:
300 if d: 316 if d:
301 opt = opt + '(' + str(d) + ')' 317 opt = opt + '(' + str(d) + ')'
302 ui.write(opt, "\n") 318 ui.write(opt, "\n")
303 if c: 319 if c:
304 ui.write(' %s\n' % c) 320 ui.write(' %s\n' % c)
305 ui.write("\n") 321
306
307 ui.write(i[0].__doc__, "\n")
308 sys.exit(0)
309 else: 322 else:
323 # program name
310 if ui.verbose: 324 if ui.verbose:
311 show_version(ui) 325 show_version(ui)
312 ui.write('\n') 326 else:
313 if ui.verbose: 327 ui.status("Mercurial Distributed SCM\n")
314 ui.write("global options:\n\n") 328 ui.status('\n')
315 for s, l, d, c in globalopts: 329
316 opt = ' ' 330 # list of commands
317 if s:
318 opt = opt + '-' + s + ' '
319 if l:
320 opt = opt + '--' + l + ' '
321 if d:
322 opt = opt + '(' + str(d) + ')'
323 ui.write(opt, "\n")
324 if c:
325 ui.write(' %s\n' % c)
326 ui.write("\n")
327
328 ui.write('hg commands:\n\n')
329
330 if cmd == "shortlist": 331 if cmd == "shortlist":
331 ui.write('basic hg commands (use "hg help" for more):\n\n') 332 ui.status('basic commands (use "hg help" '
333 'for the full list or option "-v" for details):\n\n')
334 elif ui.verbose:
335 ui.status('list of commands:\n\n')
336 else:
337 ui.status('list of commands (use "hg help -v" '
338 'to show aliases and global options):\n\n')
332 339
333 h = {} 340 h = {}
334 cmds = {} 341 cmds = {}
335 for c, e in table.items(): 342 for c, e in table.items():
336 f = c.split("|")[0] 343 f = c.split("|")[0]
337 if cmd == "shortlist" and not f.startswith("^"): 344 if cmd == "shortlist" and not f.startswith("^"):
338 continue 345 continue
346 f = f.lstrip("^")
339 if not ui.debugflag and f.startswith("debug"): 347 if not ui.debugflag and f.startswith("debug"):
340 continue 348 continue
341 f = f.lstrip("^")
342 d = "" 349 d = ""
343 if e[0].__doc__: 350 if e[0].__doc__:
344 d = e[0].__doc__.splitlines(0)[0].rstrip() 351 d = e[0].__doc__.splitlines(0)[0].rstrip()
345 h[f] = d 352 h[f] = d
346 cmds[f]=c.lstrip("^") 353 cmds[f]=c.lstrip("^")
352 if ui.verbose: 359 if ui.verbose:
353 commands = cmds[f].replace("|",", ") 360 commands = cmds[f].replace("|",", ")
354 ui.write(" %s:\n %s\n"%(commands,h[f])) 361 ui.write(" %s:\n %s\n"%(commands,h[f]))
355 else: 362 else:
356 ui.write(' %-*s %s\n' % (m, f, h[f])) 363 ui.write(' %-*s %s\n' % (m, f, h[f]))
364
365 # global options
366 if ui.verbose:
367 ui.write("\nglobal options:\n\n")
368 for s, l, d, c in globalopts:
369 opt = ' '
370 if s:
371 opt = opt + '-' + s + ' '
372 if l:
373 opt = opt + '--' + l + ' '
374 if d:
375 opt = opt + '(' + str(d) + ')'
376 ui.write(opt, "\n")
377 if c:
378 ui.write(' %s\n' % c)
357 379
358 # Commands start here, listed alphabetically 380 # Commands start here, listed alphabetically
359 381
360 def add(ui, repo, *pats, **opts): 382 def add(ui, repo, *pats, **opts):
361 '''add the specified files on the next commit''' 383 '''add the specified files on the next commit'''
1328 norepo = "clone init version help debugindex debugindexdot" 1350 norepo = "clone init version help debugindex debugindexdot"
1329 1351
1330 def find(cmd): 1352 def find(cmd):
1331 for e in table.keys(): 1353 for e in table.keys():
1332 if re.match("(%s)$" % e, cmd): 1354 if re.match("(%s)$" % e, cmd):
1333 return table[e] 1355 return e, table[e]
1334 1356
1335 raise UnknownCommand(cmd) 1357 raise UnknownCommand(cmd)
1336 1358
1337 class SignalInterrupt(Exception): 1359 class SignalInterrupt(Exception):
1338 """Exception raised on SIGTERM and SIGHUP.""" 1360 """Exception raised on SIGTERM and SIGHUP."""
1360 elif not args: 1382 elif not args:
1361 return ("help", help_, ["shortlist"], options, cmdoptions) 1383 return ("help", help_, ["shortlist"], options, cmdoptions)
1362 else: 1384 else:
1363 cmd, args = args[0], args[1:] 1385 cmd, args = args[0], args[1:]
1364 1386
1365 i = find(cmd) 1387 i = find(cmd)[1]
1366 1388
1367 # combine global options into local 1389 # combine global options into local
1368 c = list(i[1]) 1390 c = list(i[1])
1369 for o in globalopts: 1391 for o in globalopts:
1370 c.append((o[0], o[1], options[o[1]], o[3])) 1392 c.append((o[0], o[1], options[o[1]], o[3]))