~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/help.py

  • Committer: Martin Pool
  • Date: 2005-05-11 01:25:52 UTC
  • Revision ID: mbp@sourcefrog.net-20050511012552-3006222dcbf14f4e
- show command usage in help

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 + ' '
 
75
    for aname in cmdclass.takes_args:
 
76
        aname = aname.upper()
 
77
        if aname[-1] in ['$', '+']:
 
78
            aname = aname[:-1] + '...'
 
79
        elif aname[-1] == '?':
 
80
            aname = '[' + aname[:-1] + ']'
 
81
        elif aname[-1] == '*':
 
82
            aname = '[' + aname[:-1] + '...]'
 
83
        s += aname + ' '
 
84
            
 
85
    assert s[-1] == ' '
 
86
    s = s[:-1]
 
87
    
 
88
    return s
 
89
 
 
90
 
69
91
def help_on_command(cmdname):
70
92
    cmdname = str(cmdname)
71
93
 
83
105
        short = doc
84
106
        rest = ''
85
107
 
86
 
    print 'usage: bzr ' + topic,
87
 
    for aname in cmdclass.takes_args:
88
 
        aname = aname.upper()
89
 
        if aname[-1] in ['$', '+']:
90
 
            aname = aname[:-1] + '...'
91
 
        elif aname[-1] == '?':
92
 
            aname = '[' + aname[:-1] + ']'
93
 
        elif aname[-1] == '*':
94
 
            aname = '[' + aname[:-1] + '...]'
95
 
        print aname,
96
 
    print 
97
 
    print short
 
108
    print 'usage:', command_usage(topic, cmdclass)
98
109
 
99
110
    if cmdclass.aliases:
100
111
        print 'aliases: ' + ', '.join(cmdclass.aliases)
134
145
    for cmdname, cmdclass in accu:
135
146
        if cmdclass.hidden:
136
147
            continue
137
 
        print cmdname
 
148
        print command_usage(cmdname, cmdclass)
138
149
        help = inspect.getdoc(cmdclass)
139
150
        if help:
140
151
            print "    " + help.split('\n', 1)[0]