13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
# TODO: probably should say which arguments are candidates for glob
405
406
def get_help_text(self, additional_see_also=None, plain=True,
406
see_also_as_links=False):
407
see_also_as_links=False, verbose=True):
407
408
"""Return a text string with help for this command.
409
410
:param additional_see_also: Additional help topics to be
412
413
returned instead of plain text.
413
414
:param see_also_as_links: if True, convert items in 'See also'
414
415
list to internal links (used by bzr_man rstx generator)
416
:param verbose: if True, display the full help, otherwise
417
leave out the descriptive sections and just display
418
usage help (e.g. Purpose, Usage, Options) with a
419
message explaining how to obtain full help.
416
421
doc = self.help()
446
451
result += options
449
# Add the description, indenting it 2 spaces
450
# to match the indentation of the options
451
if sections.has_key(None):
452
text = sections.pop(None)
453
text = '\n '.join(text.splitlines())
454
result += ':%s:\n %s\n\n' % ('Description',text)
455
# Add the description, indenting it 2 spaces
456
# to match the indentation of the options
457
if sections.has_key(None):
458
text = sections.pop(None)
459
text = '\n '.join(text.splitlines())
460
result += ':%s:\n %s\n\n' % ('Description',text)
456
# Add the custom sections (e.g. Examples). Note that there's no need
457
# to indent these as they must be indented already in the source.
460
if sections.has_key(label):
461
result += ':%s:\n%s\n\n' % (label,sections[label])
462
# Add the custom sections (e.g. Examples). Note that there's no need
463
# to indent these as they must be indented already in the source.
466
if sections.has_key(label):
467
result += ':%s:\n%s\n' % (label,sections[label])
470
result += ("See bzr help %s for more details and examples.\n\n"
463
473
# Add the aliases, source (plug-in) and see also links, if any
595
605
if 'help' in opts: # e.g. bzr add --help
596
606
sys.stdout.write(self.get_help_text())
608
if 'usage' in opts: # e.g. bzr add --usage
609
sys.stdout.write(self.get_help_text(verbose=False))
598
611
trace.set_verbosity_level(option._verbosity_level)
599
612
if 'verbose' in self.supported_std_options:
600
613
opts['verbose'] = trace.is_verbose()
765
778
tracer = trace.Trace(count=1, trace=0)
766
779
sys.settrace(tracer.globaltrace)
780
threading.settrace(tracer.globaltrace)
769
783
return exception_to_return_code(the_callable, *args, **kwargs)
1032
1046
return ignore_pipe
1049
def main(argv=None):
1050
"""Main entry point of command-line interface.
1052
:param argv: list of unicode command-line arguments similar to sys.argv.
1053
argv[0] is script name usually, it will be ignored.
1054
Don't pass here sys.argv because this list contains plain strings
1055
and not unicode; pass None instead.
1057
:return: exit code of bzr command.
1036
1059
import bzrlib.ui
1037
1060
bzrlib.ui.ui_factory = bzrlib.ui.make_ui_for_terminal(
1038
1061
sys.stdin, sys.stdout, sys.stderr)
1041
1064
if bzrlib.version_info[3] == 'final':
1042
1065
from bzrlib import symbol_versioning
1043
1066
symbol_versioning.suppress_deprecation_warnings(override=False)
1045
user_encoding = osutils.get_user_encoding()
1046
argv = [a.decode(user_encoding) for a in argv[1:]]
1047
except UnicodeDecodeError:
1048
raise errors.BzrError(("Parameter '%r' is unsupported by the current "
1068
argv = osutils.get_unicode_argv()
1072
# ensure all arguments are unicode strings
1074
if isinstance(a, unicode):
1077
new_argv.append(a.decode('ascii'))
1078
except UnicodeDecodeError:
1079
raise errors.BzrError("argv should be list of unicode strings.")
1050
1081
ret = run_bzr_catch_errors(argv)
1051
1082
trace.mutter("return code %d", ret)