~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/help.py

  • Committer: Martin Pool
  • Date: 2005-06-29 02:55:33 UTC
  • Revision ID: mbp@sourcefrog.net-20050629025533-c8fb62423361c8a2
Patch from John:

- StringIO mixes poorly with difflib

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 
30
30
* No merge operators yet.
31
31
 
32
 
Interesting commands:
33
 
 
34
 
  bzr help [COMMAND]
35
 
      Show help screen
36
 
  bzr version
37
 
      Show software version/licence/non-warranty.
38
 
  bzr init
39
 
      Start versioning the current directory
40
 
  bzr add FILE...
41
 
      Make files versioned.
42
 
  bzr log
43
 
      Show revision history.
44
 
  bzr rename FROM TO
45
 
      Rename one file.
46
 
  bzr move FROM... DESTDIR
47
 
      Move one or more files to a different directory.
48
 
  bzr diff [FILE...]
49
 
      Show changes from last revision to working copy.
50
 
  bzr commit -m 'MESSAGE'
51
 
      Store current state as new revision.
52
 
  bzr export [-r REVNO] DESTINATION
53
 
      Export the branch state at a previous version.
54
 
  bzr status
55
 
      Show summary of pending changes.
56
 
  bzr remove FILE...
57
 
      Make a file not versioned.
58
 
  bzr info
59
 
      Show statistics about this branch.
60
 
  bzr check
61
 
      Verify history is stored safely. 
62
 
  (for more type 'bzr help commands')
 
32
 
 
33
To make a branch, use 'bzr init' in an existing directory, then 'bzr
 
34
add' to make files versioned.  'bzr add .' will recursively add all
 
35
non-ignored files.
 
36
 
 
37
'bzr status' describes files that are unknown, ignored, or modified.
 
38
'bzr diff' shows the text changes to the tree or named files.
 
39
'bzr commit -m <MESSAGE>' commits all changes in that branch.
 
40
 
 
41
'bzr move' and 'bzr rename' allow you to rename files or directories.
 
42
'bzr remove' makes a file unversioned but keeps the working copy;
 
43
to delete that too simply delete the file.
 
44
 
 
45
'bzr log' shows a history of changes, and
 
46
'bzr info' gives summary statistical information.
 
47
'bzr check' validates all files are stored safely.
 
48
 
 
49
Files can be ignored by giving a path or a glob in .bzrignore at the
 
50
top of the tree.  Use 'bzr ignored' to see what files are ignored and
 
51
why, and 'bzr unknowns' to see files that are neither versioned or
 
52
ignored.
 
53
 
 
54
For more help on any command, type 'bzr help COMMAND', or 'bzr help
 
55
commands' for a list.
63
56
"""
64
57
 
65
58
 
66
 
def help(topic=None):
 
59
import sys
 
60
 
 
61
 
 
62
def help(topic=None, outfile = None):
 
63
    if outfile == None:
 
64
        outfile = sys.stdout
67
65
    if topic == None:
68
 
        print global_help
 
66
        outfile.write(global_help)
69
67
    elif topic == 'commands':
70
 
        help_commands()
71
 
    else:
72
 
        help_on_command(topic)
73
 
 
74
 
 
75
 
def help_on_command(cmdname):
76
 
    cmdname = str(cmdname)
77
 
 
78
 
    from inspect import getdoc
79
 
    import commands
80
 
    topic, cmdclass = commands.get_cmd_class(cmdname)
81
 
 
82
 
    doc = getdoc(cmdclass)
83
 
    if doc == None:
84
 
        raise NotImplementedError("sorry, no detailed help yet for %r" % cmdname)
85
 
 
86
 
    if '\n' in doc:
87
 
        short, rest = doc.split('\n', 1)
88
 
    else:
89
 
        short = doc
90
 
        rest = ''
91
 
 
92
 
    print 'usage: bzr ' + topic,
 
68
        help_commands(outfile = outfile)
 
69
    else:
 
70
        help_on_command(topic, outfile = outfile)
 
71
 
 
72
 
 
73
def command_usage(cmdname, cmdclass):
 
74
    """Return single-line grammar for command.
 
75
 
 
76
    Only describes arguments, not options.
 
77
    """
 
78
    s = cmdname + ' '
93
79
    for aname in cmdclass.takes_args:
94
80
        aname = aname.upper()
95
81
        if aname[-1] in ['$', '+']:
98
84
            aname = '[' + aname[:-1] + ']'
99
85
        elif aname[-1] == '*':
100
86
            aname = '[' + aname[:-1] + '...]'
101
 
        print aname,
102
 
    print 
103
 
    print short
 
87
        s += aname + ' '
 
88
            
 
89
    assert s[-1] == ' '
 
90
    s = s[:-1]
 
91
    
 
92
    return s
 
93
 
 
94
 
 
95
def help_on_command(cmdname, outfile = None):
 
96
    cmdname = str(cmdname)
 
97
 
 
98
    if outfile == None:
 
99
        outfile = sys.stdout
 
100
 
 
101
    from inspect import getdoc
 
102
    import commands
 
103
    topic, cmdclass = commands.get_cmd_class(cmdname)
 
104
 
 
105
    doc = getdoc(cmdclass)
 
106
    if doc == None:
 
107
        raise NotImplementedError("sorry, no detailed help yet for %r" % cmdname)
 
108
 
 
109
    outfile.write('usage: ' + command_usage(topic, cmdclass) + '\n')
104
110
 
105
111
    if cmdclass.aliases:
106
 
        print 'aliases: ' + ', '.join(cmdclass.aliases)
107
 
    
108
 
    if rest:
109
 
        print rest
110
 
 
111
 
    help_on_option(cmdclass.takes_options)
112
 
 
113
 
 
114
 
def help_on_option(options):
 
112
        outfile.write('aliases: ' + ', '.join(cmdclass.aliases) + '\n')
 
113
    
 
114
    outfile.write(doc)
 
115
    if doc[-1] != '\n':
 
116
        outfile.write('\n')
 
117
    
 
118
    help_on_option(cmdclass.takes_options, outfile = None)
 
119
 
 
120
 
 
121
def help_on_option(options, outfile = None):
115
122
    import commands
116
123
    
117
124
    if not options:
118
125
        return
119
126
    
120
 
    print
121
 
    print 'options:'
 
127
    if outfile == None:
 
128
        outfile = sys.stdout
 
129
 
 
130
    outfile.write('\noptions:\n')
122
131
    for on in options:
123
132
        l = '    --' + on
124
133
        for shortname, longname in commands.SHORT_OPTIONS.items():
125
134
            if longname == on:
126
135
                l += ', -' + shortname
127
136
                break
128
 
        print l
129
 
 
130
 
 
131
 
def help_commands():
 
137
        outfile.write(l + '\n')
 
138
 
 
139
 
 
140
def help_commands(outfile = None):
132
141
    """List all commands"""
133
142
    import inspect
134
143
    import commands
 
144
 
 
145
    if outfile == None:
 
146
        outfile = sys.stdout
135
147
    
136
148
    accu = []
137
149
    for cmdname, cmdclass in commands.get_all_cmds():
140
152
    for cmdname, cmdclass in accu:
141
153
        if cmdclass.hidden:
142
154
            continue
143
 
        print cmdname
 
155
        outfile.write(command_usage(cmdname, cmdclass) + '\n')
144
156
        help = inspect.getdoc(cmdclass)
145
157
        if help:
146
 
            print "    " + help.split('\n', 1)[0]
 
158
            outfile.write("    " + help.split('\n', 1)[0] + '\n')
 
159
 
147
160
            
148
161