/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/help.py

  • Committer: Martin Pool
  • Date: 2005-05-05 02:59:39 UTC
  • Revision ID: mbp@sourcefrog.net-20050505025938-8399b9ca401a1176
- Split out help functions into bzrlib.help

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
"""Bazaar-NG -- a free distributed version-control tool
19
19
http://bazaar-ng.org/
20
20
 
21
 
WARNING: This is an unstable development version.
22
 
         Please keep backups.
23
 
 
24
 
Basic commands:
25
 
 
26
 
  bzr init      makes this branch versioned
27
 
  bzr branch    make a copy of another branch
28
 
 
29
 
  bzr add       make files or directories versioned
30
 
  bzr ignore    ignore a file or pattern
31
 
  bzr mv        move or rename a versioned file
32
 
 
33
 
  bzr status    summarize changes in working copy
34
 
  bzr diff      show detailed diffs
35
 
 
36
 
  bzr merge     pull in changes from another branch
37
 
  bzr commit    
38
 
 
39
 
  bzr log       show history of changes
40
 
  bzr check     validate storage
41
 
 
42
 
Use e.g. 'bzr help init' for more details, or 'bzr help commands' for
43
 
all commands.
 
21
**WARNING: THIS IS AN UNSTABLE DEVELOPMENT VERSION**
 
22
 
 
23
* Metadata format is not stable yet -- you may need to
 
24
  discard history in the future.
 
25
 
 
26
* Many commands unimplemented or partially implemented.
 
27
 
 
28
* Space-inefficient storage.
 
29
 
 
30
* No merge operators yet.
 
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')
44
63
"""
45
64
 
46
65
 
47
 
import sys
48
 
 
49
 
 
50
 
def help(topic=None, outfile = None):
51
 
    if outfile == None:
52
 
        outfile = sys.stdout
 
66
def help(topic=None):
53
67
    if topic == None:
54
 
        outfile.write(global_help)
 
68
        print global_help
55
69
    elif topic == 'commands':
56
 
        help_commands(outfile = outfile)
57
 
    else:
58
 
        help_on_command(topic, outfile = outfile)
59
 
 
60
 
 
61
 
def command_usage(cmdname, cmdclass):
62
 
    """Return single-line grammar for command.
63
 
 
64
 
    Only describes arguments, not options.
65
 
    """
66
 
    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,
67
93
    for aname in cmdclass.takes_args:
68
94
        aname = aname.upper()
69
95
        if aname[-1] in ['$', '+']:
72
98
            aname = '[' + aname[:-1] + ']'
73
99
        elif aname[-1] == '*':
74
100
            aname = '[' + aname[:-1] + '...]'
75
 
        s += aname + ' '
76
 
            
77
 
    assert s[-1] == ' '
78
 
    s = s[:-1]
79
 
    
80
 
    return s
81
 
 
82
 
 
83
 
def help_on_command(cmdname, outfile = None):
84
 
    cmdname = str(cmdname)
85
 
 
86
 
    if outfile == None:
87
 
        outfile = sys.stdout
88
 
 
89
 
    from inspect import getdoc
90
 
    import commands
91
 
    topic, cmdclass = commands.get_cmd_class(cmdname)
92
 
 
93
 
    doc = getdoc(cmdclass)
94
 
    if doc == None:
95
 
        raise NotImplementedError("sorry, no detailed help yet for %r" % cmdname)
96
 
 
97
 
    outfile.write('usage: ' + command_usage(topic, cmdclass) + '\n')
98
 
 
99
 
    if cmdclass.aliases:
100
 
        outfile.write('aliases: ' + ', '.join(cmdclass.aliases) + '\n')
101
 
    
102
 
    outfile.write(doc)
103
 
    if doc[-1] != '\n':
104
 
        outfile.write('\n')
105
 
    
106
 
    help_on_option(cmdclass.takes_options, outfile = None)
107
 
 
108
 
 
109
 
def help_on_option(options, outfile = None):
 
101
        print aname,
 
102
    print 
 
103
    print short
 
104
    if rest:
 
105
        print rest
 
106
 
 
107
    help_on_option(cmdclass.takes_options)
 
108
 
 
109
 
 
110
def help_on_option(options):
110
111
    import commands
111
112
    
112
113
    if not options:
113
114
        return
114
115
    
115
 
    if outfile == None:
116
 
        outfile = sys.stdout
117
 
 
118
 
    outfile.write('\noptions:\n')
 
116
    print
 
117
    print 'options:'
119
118
    for on in options:
120
119
        l = '    --' + on
121
120
        for shortname, longname in commands.SHORT_OPTIONS.items():
122
121
            if longname == on:
123
122
                l += ', -' + shortname
124
123
                break
125
 
        outfile.write(l + '\n')
126
 
 
127
 
 
128
 
def help_commands(outfile = None):
 
124
        print l
 
125
 
 
126
 
 
127
def help_commands():
129
128
    """List all commands"""
130
129
    import inspect
131
130
    import commands
132
 
 
133
 
    if outfile == None:
134
 
        outfile = sys.stdout
135
131
    
136
132
    accu = []
137
133
    for cmdname, cmdclass in commands.get_all_cmds():
140
136
    for cmdname, cmdclass in accu:
141
137
        if cmdclass.hidden:
142
138
            continue
143
 
        outfile.write(command_usage(cmdname, cmdclass) + '\n')
 
139
        print cmdname
144
140
        help = inspect.getdoc(cmdclass)
145
141
        if help:
146
 
            outfile.write("    " + help.split('\n', 1)[0] + '\n')
147
 
 
 
142
            print "    " + help.split('\n', 1)[0]
148
143
            
149
144