in knack/cli.py [0:0]
def __init__(self,
cli_name='cli',
config_dir=None,
config_env_var_prefix=None,
out_file=sys.stdout,
config_cls=CLIConfig,
logging_cls=CLILogging,
invocation_cls=CommandInvoker,
output_cls=OutputProducer,
completion_cls=CLICompletion,
query_cls=CLIQuery,
parser_cls=CLICommandParser,
commands_loader_cls=CLICommandsLoader,
help_cls=CLIHelp):
"""
:param cli_name: The name of the CLI (e.g. the executable name 'az')
:type cli_name: str
:param config_dir: Path to store config files for this CLI
:type config_dir: str
:param config_env_var_prefix: The prefix for configuration environment variables
:type config_env_var_prefix: str
:param out_file: File to write output to
:type out_file: file-like object
:param config_cls: Class to handle configuration
:type config_cls: knack.config.CLIConfig
:param logging_cls: Class to handle logging
:type logging_cls: knack.log.CLILogging
:param invocation_cls: Class to handle command invocations
:type invocation_cls: knack.invocation.CommandInvoker
:param output_cls: Class to handle output processing of commands
:type output_cls: knack.output.OutputProducer
:param completion_cls: Class to handle completions
:type completion_cls: knack.completion.CLICompletion
:param query_cls: Class to handle command queries
:type query_cls: knack.query.CLIQuery
:param parser_cls: Class to handler command parsing
:type parser_cls: knack.parser.CLICommandParser
:param commands_loader_cls: Class to handle loading commands
:type commands_loader_cls: knack.commands.CLICommandsLoader
:param help_cls: Class to handle help
:type help_cls: knack.help.CLIHelp
"""
self.name = cli_name
self.out_file = out_file
self.config_cls = config_cls
self.logging_cls = logging_cls
self.output_cls = output_cls
self.parser_cls = parser_cls
self.help_cls = help_cls
self.commands_loader_cls = commands_loader_cls
self.invocation_cls = invocation_cls
self.invocation = None
self._event_handlers = defaultdict(lambda: [])
# Data that's typically backed to persistent storage
self.config = config_cls(
config_dir=config_dir or os.path.expanduser(os.path.join('~', '.{}'.format(cli_name))),
config_env_var_prefix=config_env_var_prefix or cli_name.upper()
)
# In memory collection of key-value data for this current cli. This persists between invocations.
self.data = defaultdict(lambda: None)
self.completion = completion_cls(cli_ctx=self)
self.logging = logging_cls(self.name, cli_ctx=self)
self.output = self.output_cls(cli_ctx=self)
self.result = None
self.query = query_cls(cli_ctx=self)
# As logging is initialized in `invoke`, call `logger.debug` or `logger.info` here won't work.
self.init_debug_log = []
self.init_info_log = []
self.only_show_errors = self.config.getboolean('core', 'only_show_errors', fallback=False)
self.enable_color = self._should_enable_color()
# Init colorama only in Windows legacy terminal
self._should_init_colorama = self.enable_color and sys.platform == 'win32' and not is_modern_terminal()