Mercurial > public > mercurial-scm > hg
comparison mercurial/commands.py @ 16781:c0b98f436cce
help: move some helper functions to help.py
author | Olav Reinert <seroton10@gmail.com> |
---|---|
date | Tue, 22 May 2012 22:08:41 +0200 |
parents | d064da05590d |
children | ba512212dab1 |
comparison
equal
deleted
inserted
replaced
16780:d064da05590d | 16781:c0b98f436cce |
---|---|
3087 Returns 0 if successful. | 3087 Returns 0 if successful. |
3088 """ | 3088 """ |
3089 | 3089 |
3090 textwidth = min(ui.termwidth(), 80) - 2 | 3090 textwidth = min(ui.termwidth(), 80) - 2 |
3091 | 3091 |
3092 def optrst(options, verbose): | |
3093 data = [] | |
3094 multioccur = False | |
3095 for option in options: | |
3096 if len(option) == 5: | |
3097 shortopt, longopt, default, desc, optlabel = option | |
3098 else: | |
3099 shortopt, longopt, default, desc = option | |
3100 optlabel = _("VALUE") # default label | |
3101 | |
3102 if _("DEPRECATED") in desc and not verbose: | |
3103 continue | |
3104 | |
3105 so = '' | |
3106 if shortopt: | |
3107 so = '-' + shortopt | |
3108 lo = '--' + longopt | |
3109 if default: | |
3110 desc += _(" (default: %s)") % default | |
3111 | |
3112 if isinstance(default, list): | |
3113 lo += " %s [+]" % optlabel | |
3114 multioccur = True | |
3115 elif (default is not None) and not isinstance(default, bool): | |
3116 lo += " %s" % optlabel | |
3117 | |
3118 data.append((so, lo, desc)) | |
3119 | |
3120 rst = minirst.maketable(data, 1) | |
3121 | |
3122 if multioccur: | |
3123 rst += _("\n[+] marked option can be specified multiple times\n") | |
3124 | |
3125 return rst | |
3126 | |
3127 # list all option lists | |
3128 def opttext(optlist, width, verbose): | |
3129 rst = '' | |
3130 if not optlist: | |
3131 return '' | |
3132 | |
3133 for title, options in optlist: | |
3134 rst += '\n%s\n' % title | |
3135 if options: | |
3136 rst += "\n" | |
3137 rst += optrst(options, verbose) | |
3138 rst += '\n' | |
3139 | |
3140 return '\n' + minirst.format(rst, width) | |
3141 | |
3142 def addglobalopts(optlist, aliases): | 3092 def addglobalopts(optlist, aliases): |
3143 if ui.quiet: | 3093 if ui.quiet: |
3144 return [] | 3094 return [] |
3145 | 3095 |
3146 if ui.verbose: | 3096 if ui.verbose: |
3221 # options | 3171 # options |
3222 if not ui.quiet and entry[1]: | 3172 if not ui.quiet and entry[1]: |
3223 rst += '\n' | 3173 rst += '\n' |
3224 rst += _("options:") | 3174 rst += _("options:") |
3225 rst += '\n\n' | 3175 rst += '\n\n' |
3226 rst += optrst(entry[1], ui.verbose) | 3176 rst += help.optrst(entry[1], ui.verbose) |
3227 | 3177 |
3228 if ui.verbose: | 3178 if ui.verbose: |
3229 rst += '\n' | 3179 rst += '\n' |
3230 rst += _("global options:") | 3180 rst += _("global options:") |
3231 rst += '\n\n' | 3181 rst += '\n\n' |
3232 rst += optrst(globalopts, ui.verbose) | 3182 rst += help.optrst(globalopts, ui.verbose) |
3233 | 3183 |
3234 keep = ui.verbose and ['verbose'] or [] | 3184 keep = ui.verbose and ['verbose'] or [] |
3235 formatted, pruned = minirst.format(rst, textwidth, keep=keep) | 3185 formatted, pruned = minirst.format(rst, textwidth, keep=keep) |
3236 ui.write(formatted) | 3186 ui.write(formatted) |
3237 | 3187 |
3302 for t, desc in topics: | 3252 for t, desc in topics: |
3303 ui.write(" %-*s %s\n" % (topics_len, t, desc)) | 3253 ui.write(" %-*s %s\n" % (topics_len, t, desc)) |
3304 | 3254 |
3305 optlist = [] | 3255 optlist = [] |
3306 addglobalopts(optlist, True) | 3256 addglobalopts(optlist, True) |
3307 ui.write(opttext(optlist, textwidth, ui.verbose)) | 3257 ui.write(help.opttext(optlist, textwidth, ui.verbose)) |
3308 | 3258 |
3309 def helptopic(name): | 3259 def helptopic(name): |
3310 for names, header, doc in help.helptable: | 3260 for names, header, doc in help.helptable: |
3311 if name in names: | 3261 if name in names: |
3312 break | 3262 break |