def _match_long_opt(self, opt, explicit_value, state): if opt not in self._long_opt: from q2cli.util import get_close_matches # This is way better than substring matching possibilities = get_close_matches(opt, self._long_opt) raise exceptions.NoSuchOption(opt, possibilities=possibilities, ctx=self.ctx) return super()._match_long_opt(opt, explicit_value, state)
def get_command(self, ctx, name): try: action = self._action_lookup[name] except KeyError: from q2cli.util import get_close_matches possibilities = get_close_matches(name, self._action_lookup) if len(possibilities) == 1: hint = ' Did you mean %r?' % possibilities[0] elif possibilities: hint = ' (Possible commands: %s)' % ', '.join(possibilities) else: hint = '' click.echo(CONFIG.cfg_style( 'error', "Error: QIIME 2 plugin %r has no " "action %r." % (self._plugin['name'], name) + hint), err=True) ctx.exit(2) # Match exit code of `return None` return ActionCommand(name, self._plugin, action)
def get_command(self, ctx, name): if name in self._builtin_commands: return self._builtin_commands[name] try: plugin = self._plugin_lookup[name] except KeyError: from q2cli.util import get_close_matches possibilities = get_close_matches(name, self._plugin_lookup) if len(possibilities) == 1: hint = ' Did you mean %r?' % possibilities[0] elif possibilities: hint = ' (Possible commands: %s)' % ', '.join(possibilities) else: hint = '' click.echo(CONFIG.cfg_style( 'error', "Error: QIIME 2 has no " "plugin/command named %r." % name + hint), err=True) ctx.exit(2) # Match exit code of `return None` return PluginCommand(plugin, name)