/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 breezy/plugins/bash_completion/bashcomp.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-11-16 18:59:44 UTC
  • mfrom: (7143.15.15 more-cleanups)
  • Revision ID: breezy.the.bot@gmail.com-20181116185944-biefv1sub37qfybm
Sprinkle some PEP8iness.

Merged from https://code.launchpad.net/~jelmer/brz/more-cleanups/+merge/358611

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
shopt -s progcomp
61
61
%(function)s
62
62
complete -F %(function_name)s -o default brz
63
 
"""     % {
 
63
""" % {
64
64
            "function_name": self.function_name,
65
65
            "function": self.function(),
66
66
            "brz_version": self.brz_version(),
157
157
 
158
158
        return 0
159
159
}
160
 
"""     % {
 
160
""" % {
161
161
            "cmds": self.command_names(),
162
162
            "function_name": self.function_name,
163
163
            "cases": self.command_cases(),
303
303
            self.selected_plugins = None
304
304
        else:
305
305
            self.selected_plugins = {x.replace('-', '_')
306
 
                                         for x in selected_plugins}
 
306
                                     for x in selected_plugins}
307
307
 
308
308
    def collect(self):
309
309
        self.global_options()
337
337
        plugin_name = cmd.plugin_name()
338
338
        if plugin_name is not None:
339
339
            if (self.selected_plugins is not None and
340
 
                plugin not in self.selected_plugins):
 
340
                    plugin not in self.selected_plugins):
341
341
                return None
342
342
            plugin_data = self.data.plugins.get(plugin_name)
343
343
            if plugin_data is None:
352
352
        # ones while maintaining the actual command name unchanged.
353
353
        cmd_data.aliases.extend(cmd.aliases)
354
354
        cmd_data.aliases.extend(sorted([useralias
355
 
            for cmdalias in cmd_data.aliases
356
 
            if cmdalias in self.user_aliases
357
 
            for useralias in self.user_aliases[cmdalias]
358
 
            if useralias not in cmd_data.aliases]))
 
355
                                        for cmdalias in cmd_data.aliases
 
356
                                        if cmdalias in self.user_aliases
 
357
                                        for useralias in self.user_aliases[cmdalias]
 
358
                                        if useralias not in cmd_data.aliases]))
359
359
 
360
360
        opts = cmd.options()
361
361
        for optname, opt in sorted(opts.items()):
363
363
 
364
364
        if 'help' == name or 'help' in cmd.aliases:
365
365
            cmd_data.fixed_words = ('($cmds %s)' %
366
 
                " ".join(sorted(help_topics.topic_registry.keys())))
 
366
                                    " ".join(sorted(help_topics.topic_registry.keys())))
367
367
 
368
368
        return cmd_data
369
369
 
394
394
 
395
395
    def wrap_parser(self, optswitches, parser):
396
396
        orig_add_option_group = parser.add_option_group
 
397
 
397
398
        def tweaked_add_option_group(*opts, **attrs):
398
399
            return self.wrap_container(optswitches,
399
 
                orig_add_option_group(*opts, **attrs))
 
400
                                       orig_add_option_group(*opts, **attrs))
400
401
        parser.add_option_group = tweaked_add_option_group
401
402
        return self.wrap_container(optswitches, parser)
402
403
 
404
405
def bash_completion_function(out, function_name="_brz", function_only=False,
405
406
                             debug=False,
406
407
                             no_plugins=False, selected_plugins=None):
407
 
    dc = DataCollector(no_plugins=no_plugins, selected_plugins=selected_plugins)
 
408
    dc = DataCollector(no_plugins=no_plugins,
 
409
                       selected_plugins=selected_plugins)
408
410
    data = dc.collect()
409
411
    cg = BashCodeGen(data, function_name=function_name, debug=debug)
410
412
    if function_only:
427
429
 
428
430
    takes_options = [
429
431
        option.Option("function-name", short_name="f", type=text_type, argname="name",
430
 
               help="Name of the generated function (default: _brz)"),
 
432
                      help="Name of the generated function (default: _brz)"),
431
433
        option.Option("function-only", short_name="o", type=None,
432
 
               help="Generate only the shell function, don't enable it"),
 
434
                      help="Generate only the shell function, don't enable it"),
433
435
        option.Option("debug", type=None, hidden=True,
434
 
               help="Enable shell code useful for debugging"),
 
436
                      help="Enable shell code useful for debugging"),
435
437
        option.ListOption("plugin", type=text_type, argname="name",
436
 
                # param_name="selected_plugins", # doesn't work, bug #387117
437
 
                help="Enable completions for the selected plugin"
438
 
                + " (default: all plugins)"),
 
438
                          # param_name="selected_plugins", # doesn't work, bug #387117
 
439
                          help="Enable completions for the selected plugin"
 
440
                          + " (default: all plugins)"),
439
441
        ]
440
442
 
441
443
    def run(self, **kwargs):