~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/help.py

  • Committer: Martin Pool
  • Date: 2005-05-05 06:38:18 UTC
  • Revision ID: mbp@sourcefrog.net-20050505063818-3eb3260343878325
- do upload CHANGELOG to web server, even though it's autogenerated

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 
30
30
* No merge operators yet.
31
31
 
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.
 
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')
56
63
"""
57
64
 
58
65
 
59
 
import sys
60
 
 
61
 
 
62
 
def help(topic=None, outfile = None):
63
 
    if outfile == None:
64
 
        outfile = sys.stdout
 
66
def help(topic=None):
65
67
    if topic == None:
66
 
        outfile.write(global_help)
 
68
        print global_help
67
69
    elif topic == 'commands':
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 + ' '
 
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,
79
93
    for aname in cmdclass.takes_args:
80
94
        aname = aname.upper()
81
95
        if aname[-1] in ['$', '+']:
84
98
            aname = '[' + aname[:-1] + ']'
85
99
        elif aname[-1] == '*':
86
100
            aname = '[' + aname[:-1] + '...]'
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')
 
101
        print aname,
 
102
    print 
 
103
    print short
110
104
 
111
105
    if cmdclass.aliases:
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):
 
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):
122
115
    import commands
123
116
    
124
117
    if not options:
125
118
        return
126
119
    
127
 
    if outfile == None:
128
 
        outfile = sys.stdout
129
 
 
130
 
    outfile.write('\noptions:\n')
 
120
    print
 
121
    print 'options:'
131
122
    for on in options:
132
123
        l = '    --' + on
133
124
        for shortname, longname in commands.SHORT_OPTIONS.items():
134
125
            if longname == on:
135
126
                l += ', -' + shortname
136
127
                break
137
 
        outfile.write(l + '\n')
138
 
 
139
 
 
140
 
def help_commands(outfile = None):
 
128
        print l
 
129
 
 
130
 
 
131
def help_commands():
141
132
    """List all commands"""
142
133
    import inspect
143
134
    import commands
144
 
 
145
 
    if outfile == None:
146
 
        outfile = sys.stdout
147
135
    
148
136
    accu = []
149
137
    for cmdname, cmdclass in commands.get_all_cmds():
152
140
    for cmdname, cmdclass in accu:
153
141
        if cmdclass.hidden:
154
142
            continue
155
 
        outfile.write(command_usage(cmdname, cmdclass) + '\n')
 
143
        print cmdname
156
144
        help = inspect.getdoc(cmdclass)
157
145
        if help:
158
 
            outfile.write("    " + help.split('\n', 1)[0] + '\n')
159
 
 
 
146
            print "    " + help.split('\n', 1)[0]
160
147
            
161
148