~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: Robert J. Tanner
  • Date: 2009-06-10 03:56:49 UTC
  • mfrom: (4423 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4425.
  • Revision ID: tanner@real-time.com-20090610035649-7rfx4cls4550zc3c
Merge 1.15.1 back to trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
952
952
    return ignore_pipe
953
953
 
954
954
 
955
 
def main(argv):
 
955
def main(argv=None):
 
956
    """Main entry point of command-line interface.
 
957
 
 
958
    :param argv: list of unicode command-line arguments similar to sys.argv.
 
959
        argv[0] is script name usually, it will be ignored.
 
960
        Don't pass here sys.argv because this list contains plain strings
 
961
        and not unicode; pass None instead.
 
962
 
 
963
    :return: exit code of bzr command.
 
964
    """
956
965
    import bzrlib.ui
957
966
    bzrlib.ui.ui_factory = bzrlib.ui.make_ui_for_terminal(
958
967
        sys.stdin, sys.stdout, sys.stderr)
961
970
    if bzrlib.version_info[3] == 'final':
962
971
        from bzrlib import symbol_versioning
963
972
        symbol_versioning.suppress_deprecation_warnings(override=False)
964
 
    try:
965
 
        user_encoding = osutils.get_user_encoding()
966
 
        argv = [a.decode(user_encoding) for a in argv[1:]]
967
 
    except UnicodeDecodeError:
968
 
        raise errors.BzrError(("Parameter '%r' is unsupported by the current "
969
 
                                                            "encoding." % a))
 
973
    if argv is None:
 
974
        argv = osutils.get_unicode_argv()
 
975
    else:
 
976
        new_argv = []
 
977
        try:
 
978
            # ensure all arguments are unicode strings
 
979
            for a in argv[1:]:
 
980
                if isinstance(a, unicode):
 
981
                    new_argv.append(a)
 
982
                else:
 
983
                    new_argv.append(a.decode('ascii'))
 
984
        except UnicodeDecodeError:
 
985
            raise errors.BzrError("argv should be list of unicode strings.")
 
986
        argv = new_argv
970
987
    ret = run_bzr_catch_errors(argv)
971
988
    trace.mutter("return code %d", ret)
972
989
    return ret