mercurial/commands.py
changeset 4315 bc6f5a1d8b7b
parent 4273 8185a1ca8628
child 4322 38922a13101e
equal deleted inserted replaced
4314:43dedce9667e 4315:bc6f5a1d8b7b
  1266 
  1266 
  1267     Given an extension name, print help for that extension, and the
  1267     Given an extension name, print help for that extension, and the
  1268     commands it provides."""
  1268     commands it provides."""
  1269     option_lists = []
  1269     option_lists = []
  1270 
  1270 
       
  1271     def addglobalopts(aliases):
       
  1272         if ui.verbose:
       
  1273             option_lists.append((_("global options:"), globalopts))
       
  1274             if name == 'shortlist':
       
  1275                 option_lists.append((_('use "hg help" for the full list '
       
  1276                                        'of commands'), ()))
       
  1277         else:
       
  1278             if name == 'shortlist':
       
  1279                 msg = _('use "hg help" for the full list of commands '
       
  1280                         'or "hg -v" for details')
       
  1281             elif aliases:
       
  1282                 msg = _('use "hg -v help%s" to show aliases and '
       
  1283                         'global options') % (name and " " + name or "")
       
  1284             else:
       
  1285                 msg = _('use "hg -v help %s" to show global options') % name
       
  1286             option_lists.append((msg, ()))
       
  1287 
  1271     def helpcmd(name):
  1288     def helpcmd(name):
  1272         if with_version:
  1289         if with_version:
  1273             version_(ui)
  1290             version_(ui)
  1274             ui.write('\n')
  1291             ui.write('\n')
  1275         aliases, i = findcmd(ui, name)
  1292         aliases, i = findcmd(ui, name)
  1289             if len(aliases) > 1:
  1306             if len(aliases) > 1:
  1290                 ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:]))
  1307                 ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:]))
  1291 
  1308 
  1292             # options
  1309             # options
  1293             if i[1]:
  1310             if i[1]:
  1294                 option_lists.append(("options", i[1]))
  1311                 option_lists.append((_("options:\n"), i[1]))
       
  1312 
       
  1313             addglobalopts(False)
  1295 
  1314 
  1296     def helplist(select=None):
  1315     def helplist(select=None):
  1297         h = {}
  1316         h = {}
  1298         cmds = {}
  1317         cmds = {}
  1299         for c, e in table.items():
  1318         for c, e in table.items():
  1319                 commands = cmds[f].replace("|",", ")
  1338                 commands = cmds[f].replace("|",", ")
  1320                 ui.write(" %s:\n      %s\n"%(commands, h[f]))
  1339                 ui.write(" %s:\n      %s\n"%(commands, h[f]))
  1321             else:
  1340             else:
  1322                 ui.write(' %-*s   %s\n' % (m, f, h[f]))
  1341                 ui.write(' %-*s   %s\n' % (m, f, h[f]))
  1323 
  1342 
       
  1343         if not ui.quiet:
       
  1344             addglobalopts(True)
       
  1345 
  1324     def helptopic(name):
  1346     def helptopic(name):
  1325         v = None
  1347         v = None
  1326         for i in help.helptable:
  1348         for i in help.helptable:
  1327             l = i.split('|')
  1349             l = i.split('|')
  1328             if name in l:
  1350             if name in l:
  1358             ct = mod.cmdtable
  1380             ct = mod.cmdtable
  1359         except AttributeError:
  1381         except AttributeError:
  1360             ui.status(_('no commands defined\n'))
  1382             ui.status(_('no commands defined\n'))
  1361             return
  1383             return
  1362 
  1384 
  1363         if ui.verbose:
  1385         ui.status(_('list of commands:\n\n'))
  1364             ui.status(_('list of commands:\n\n'))
       
  1365         else:
       
  1366             ui.status(_('list of commands (use "hg help -v %s" '
       
  1367                         'to show aliases and global options):\n\n') % name)
       
  1368 
       
  1369         modcmds = dict.fromkeys([c.split('|', 1)[0] for c in ct])
  1386         modcmds = dict.fromkeys([c.split('|', 1)[0] for c in ct])
  1370         helplist(modcmds.has_key)
  1387         helplist(modcmds.has_key)
  1371 
  1388 
  1372     if name and name != 'shortlist':
  1389     if name and name != 'shortlist':
  1373         i = None
  1390         i = None
  1389             ui.status(_("Mercurial Distributed SCM\n"))
  1406             ui.status(_("Mercurial Distributed SCM\n"))
  1390         ui.status('\n')
  1407         ui.status('\n')
  1391 
  1408 
  1392         # list of commands
  1409         # list of commands
  1393         if name == "shortlist":
  1410         if name == "shortlist":
  1394             ui.status(_('basic commands (use "hg help" '
  1411             ui.status(_('basic commands:\n\n'))
  1395                         'for the full list or option "-v" for details):\n\n'))
  1412         else:
  1396         elif ui.verbose:
       
  1397             ui.status(_('list of commands:\n\n'))
  1413             ui.status(_('list of commands:\n\n'))
  1398         else:
       
  1399             ui.status(_('list of commands (use "hg help -v" '
       
  1400                         'to show aliases and global options):\n\n'))
       
  1401 
  1414 
  1402         helplist()
  1415         helplist()
  1403 
       
  1404     # global options
       
  1405     if ui.verbose:
       
  1406         option_lists.append(("global options", globalopts))
       
  1407 
  1416 
  1408     # list all option lists
  1417     # list all option lists
  1409     opt_output = []
  1418     opt_output = []
  1410     for title, options in option_lists:
  1419     for title, options in option_lists:
  1411         opt_output.append(("\n%s:\n" % title, None))
  1420         opt_output.append(("\n%s" % title, None))
  1412         for shortopt, longopt, default, desc in options:
  1421         for shortopt, longopt, default, desc in options:
  1413             if "DEPRECATED" in desc and not ui.verbose: continue
  1422             if "DEPRECATED" in desc and not ui.verbose: continue
  1414             opt_output.append(("%2s%s" % (shortopt and "-%s" % shortopt,
  1423             opt_output.append(("%2s%s" % (shortopt and "-%s" % shortopt,
  1415                                           longopt and " --%s" % longopt),
  1424                                           longopt and " --%s" % longopt),
  1416                                "%s%s" % (desc,
  1425                                "%s%s" % (desc,
  1417                                          default
  1426                                          default
  1418                                          and _(" (default: %s)") % default
  1427                                          and _(" (default: %s)") % default
  1419                                          or "")))
  1428                                          or "")))
  1420 
  1429 
  1421     if opt_output:
  1430     if opt_output:
  1422         opts_len = max([len(line[0]) for line in opt_output if line[1]])
  1431         opts_len = max([len(line[0]) for line in opt_output if line[1]] or [0])
  1423         for first, second in opt_output:
  1432         for first, second in opt_output:
  1424             if second:
  1433             if second:
  1425                 ui.write(" %-*s  %s\n" % (opts_len, first, second))
  1434                 ui.write(" %-*s  %s\n" % (opts_len, first, second))
  1426             else:
  1435             else:
  1427                 ui.write("%s\n" % first)
  1436                 ui.write("%s\n" % first)