~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bashcomp.py

List versions of bzr and plugins.

This should help in cases where the script is distributed across different
bzr setups, so people know whether things match or not.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
    option,
26
26
    plugin,
27
27
)
 
28
import bzrlib
28
29
import re
29
30
 
30
31
head="""\
39
40
# Generated using the bzr-bash-completion plugin version %(version)s.
40
41
# See https://launchpad.net/bzr-bash-completion for details.
41
42
 
 
43
# Commands and options of bzr %(bzr_version)s
 
44
 
42
45
shopt -s progcomp
43
46
"""
44
47
fun="""\
144
147
    cmds = []
145
148
    cases = ""
146
149
    reqarg = {}
 
150
    plugins = set()
147
151
 
148
152
    re_switch = re.compile(r'\n(--[A-Za-z0-9-_]+)(?:, (-\S))?\s')
149
153
    help_text = help_topics.topic_registry.get_detail('global-options')
180
184
        cmds.extend(aliases)
181
185
        plugin = cmd.plugin_name()
182
186
        if plugin is not None:
 
187
            plugins.add(plugin)
183
188
            cases += "\t\t# plugin \"%s\"\n" % plugin
184
189
        opts = cmd.options()
185
190
        switches = []
216
221
            cases += "\n\t\t\t".join(enums)
217
222
            cases += "\n\t\tesac\n"
218
223
        cases += "\t\t;;\n"
 
224
 
 
225
    bzr_version = bzrlib.version_string
 
226
    if not plugins:
 
227
        bzr_version += "."
 
228
    else:
 
229
        bzr_version += " and the following plugins:"
 
230
        for plugin in sorted(plugins):
 
231
            pv = bzrlib.plugin.plugins()[plugin].__version__
 
232
            if pv == 'unknown':
 
233
                pv = ''
 
234
            else:
 
235
                pv = ' ' + pv
 
236
                bzr_version += "\n# %s%s" % (plugin, pv)
 
237
 
219
238
    if function_only:
220
239
        template = fun
221
240
    else:
226
245
                          "version": __version__,
227
246
                          "global_options": global_options,
228
247
                          "debug": debug_output if debug else "",
 
248
                          "bzr_version": bzr_version,
229
249
                          })
230
250
 
231
251
if __name__ == '__main__':