~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/help.py

  • Committer: Martin Pool
  • Date: 2005-05-10 08:15:58 UTC
  • Revision ID: mbp@sourcefrog.net-20050510081558-9a38e2c46ba4ebc4
- Patch from Fredrik Lundh to check Python version and 
  try to find a better one if it's too old.

  Patched to try to prevent infinite loops in wierd configurations,
  and to log to stderr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
        help_on_command(topic)
67
67
 
68
68
 
69
 
def command_usage(cmdname, cmdclass):
70
 
    """Return single-line grammar for command.
71
 
 
72
 
    Only describes arguments, not options.
73
 
    """
74
 
    s = cmdname + ' '
 
69
def help_on_command(cmdname):
 
70
    cmdname = str(cmdname)
 
71
 
 
72
    from inspect import getdoc
 
73
    import commands
 
74
    topic, cmdclass = commands.get_cmd_class(cmdname)
 
75
 
 
76
    doc = getdoc(cmdclass)
 
77
    if doc == None:
 
78
        raise NotImplementedError("sorry, no detailed help yet for %r" % cmdname)
 
79
 
 
80
    if '\n' in doc:
 
81
        short, rest = doc.split('\n', 1)
 
82
    else:
 
83
        short = doc
 
84
        rest = ''
 
85
 
 
86
    print 'usage: bzr ' + topic,
75
87
    for aname in cmdclass.takes_args:
76
88
        aname = aname.upper()
77
89
        if aname[-1] in ['$', '+']:
80
92
            aname = '[' + aname[:-1] + ']'
81
93
        elif aname[-1] == '*':
82
94
            aname = '[' + aname[:-1] + '...]'
83
 
        s += aname + ' '
84
 
            
85
 
    assert s[-1] == ' '
86
 
    s = s[:-1]
87
 
    
88
 
    return s
89
 
 
90
 
 
91
 
def help_on_command(cmdname):
92
 
    cmdname = str(cmdname)
93
 
 
94
 
    from inspect import getdoc
95
 
    import commands
96
 
    topic, cmdclass = commands.get_cmd_class(cmdname)
97
 
 
98
 
    doc = getdoc(cmdclass)
99
 
    if doc == None:
100
 
        raise NotImplementedError("sorry, no detailed help yet for %r" % cmdname)
101
 
 
102
 
    print 'usage:', command_usage(topic, cmdclass)
 
95
        print aname,
 
96
    print 
 
97
    print short
103
98
 
104
99
    if cmdclass.aliases:
105
100
        print 'aliases: ' + ', '.join(cmdclass.aliases)
106
101
    
107
 
    print doc
108
 
    
 
102
    if rest:
 
103
        print rest
 
104
 
109
105
    help_on_option(cmdclass.takes_options)
110
106
 
111
107
 
138
134
    for cmdname, cmdclass in accu:
139
135
        if cmdclass.hidden:
140
136
            continue
141
 
        print command_usage(cmdname, cmdclass)
 
137
        print cmdname
142
138
        help = inspect.getdoc(cmdclass)
143
139
        if help:
144
140
            print "    " + help.split('\n', 1)[0]