def __init__( self, name, command_pkgs=None, plugin: typing.Optional[PluginInterface] = None, testing: bool = False, options: typing.Optional[Options] = None, ): self._name = name self._plugin = plugin or PluginInterface() self._options = options or Options() assert isinstance(self._plugin, PluginInterface) self._blacklist = self._plugin.getBlacklistPlugin() self._command_pkgs = command_pkgs if self._blacklist is not None: assert isinstance(self._blacklist, CommandBlacklist) self._testing = testing # Setting the context to be global context._ctx = self._plugin.create_context() self._ctx = context.get_context() assert isinstance(self._ctx, context.Context) # Setting the binary name self._ctx.set_binary_name(self._name) # Load, setup the usagelogger self._usagelogger = None
def __init__(self, name, plugin=None, testing=False): self._name = name self._plugin = plugin or PluginInterface() assert isinstance(self._plugin, PluginInterface) self._blacklist = self._plugin.getBlacklistPlugin() if self._blacklist is not None: assert isinstance(self._blacklist, CommandBlacklist) self._testing = testing # Setting the context to be global context._ctx = self._plugin.create_context() self._ctx = context.get_context() assert isinstance(self._ctx, context.Context) # Setting the binary name self._ctx.set_binary_name(self._name) # Load, setup the usagelogger self._usagelogger = None self._opts_parser = self._plugin.get_opts_parser() SubParser = create_subparser_class(self._opts_parser) self._opts_parser.add_argument( "--_print-completion-model", action="store_true", help=argparse.SUPPRESS, ) cmd_parser = self._opts_parser.add_subparsers( dest="_cmd", help="Subcommand to run, if missing the interactive mode is started" " instead.", parser_class=SubParser, metavar="[command]", ) builtin_cmds = [ builtin.Connect, builtin.Exit, builtin.Verbose, help.HelpCommand, ] listeners = self._plugin.get_listeners() self._registry = CommandsRegistry(cmd_parser, listeners) self._ctx.set_registry(self._registry) self._registry.register_priority_listener(self._ctx) # register built-in commands for cmd in builtin_cmds: self._registry.register_command(cmd()) # load commands from plugin for cmd in self._plugin.get_commands(): self._registry.register_command(cmd, override=True) # By default, if we didn't receive any command we will use the connect # command which drops us to an interactive mode. self._opts_parser.set_default_subparser("connect")
def registry(self): return context.get_context().registry
def run_interactive(self, cmd, args, raw): ctx = context.get_context() if args: ctx.set_verbose(args) else: print("Current verbosity: {}".format(ctx.args.verbose))