/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: Robert Collins
  • Date: 2006-03-03 02:09:49 UTC
  • mto: (1594.2.4 integration)
  • mto: This revision was merged to the branch mainline in revision 1596.
  • Revision ID: robertc@robertcollins.net-20060303020949-0ddc6f33d0a43943
Smoke test for RevisionStore factories creating revision stores.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 by Canonical Ltd
2
 
#
 
1
# Copyright (C) 2004, 2005 by Canonical Ltd
 
2
 
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
#
 
7
 
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
12
 
#
 
12
 
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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
18
# TODO: probably should say which arguments are candidates for glob
19
19
# expansion on windows and do that at the command level.
20
20
 
 
21
# TODO: Help messages for options.
 
22
 
21
23
# TODO: Define arguments by objects, rather than just using names.
22
24
# Those objects can specify the expected type of the argument, which
23
 
# would help with validation and shell completion.  They could also provide
24
 
# help/explanation for that argument in a structured way.
25
 
 
26
 
# TODO: Specific "examples" property on commands for consistent formatting.
 
25
# would help with validation and shell completion.
27
26
 
28
27
# TODO: "--profile=cum", to change sort order.  Is there any value in leaving
29
28
# the profile output behind so it can be interactively examined?
31
30
import sys
32
31
import os
33
32
from warnings import warn
 
33
from inspect import getdoc
34
34
import errno
35
35
 
36
36
import bzrlib
37
 
from bzrlib.errors import (BzrError,
 
37
from bzrlib.errors import (BzrError, 
38
38
                           BzrCheckError,
39
39
                           BzrCommandError,
40
40
                           BzrOptionError,
49
49
 
50
50
 
51
51
def register_command(cmd, decorate=False):
52
 
    """Utility function to help register a command
53
 
 
54
 
    :param cmd: Command subclass to register
55
 
    :param decorate: If true, allow overriding an existing command
56
 
        of the same name; the old command is returned by this function.
57
 
        Otherwise it is an error to try to override an existing command.
58
 
    """
 
52
    "Utility function to help register a command"
59
53
    global plugin_cmds
60
54
    k = cmd.__name__
61
55
    if k.startswith("cmd_"):
64
58
        k_unsquished = k
65
59
    if not plugin_cmds.has_key(k_unsquished):
66
60
        plugin_cmds[k_unsquished] = cmd
67
 
        mutter('registered plugin command %s', k_unsquished)
 
61
        mutter('registered plugin command %s', k_unsquished)      
68
62
        if decorate and k_unsquished in builtin_command_names():
69
63
            return _builtin_commands()[k_unsquished]
70
64
    elif decorate:
91
85
    builtins = bzrlib.builtins.__dict__
92
86
    for name in builtins:
93
87
        if name.startswith("cmd_"):
94
 
            real_name = _unsquish_command_name(name)
 
88
            real_name = _unsquish_command_name(name)        
95
89
            r[real_name] = builtins[name]
96
90
    return r
 
91
 
97
92
            
98
93
 
99
94
def builtin_command_names():
255
250
        shell error code if not.  It's OK for this method to allow
256
251
        an exception to raise up.
257
252
        """
258
 
        raise NotImplementedError('no implementation of command %r' 
259
 
                                  % self.name())
 
253
        raise NotImplementedError()
 
254
 
260
255
 
261
256
    def help(self):
262
257
        """Return help message for this class."""
263
 
        from inspect import getdoc
264
258
        if self.__doc__ is Command.__doc__:
265
259
            return None
266
260
        return getdoc(self)
568
562
        i += 1
569
563
 
570
564
    argv = argv_copy
571
 
    if (not argv):
572
 
        from bzrlib.builtins import cmd_help
573
 
        cmd_help().run_argv([])
 
565
    if (not argv) or (argv[0] == '--help'):
 
566
        from bzrlib.help import help
 
567
        if len(argv) > 1:
 
568
            help(argv[1])
 
569
        else:
 
570
            help()
574
571
        return 0
575
572
 
576
573
    if argv[0] == '--version':