def __init__(self, options): # Load config. c = self.config = get_config(options.mssqlclirc_file) self.initialize_logging() self.logger = logging.getLogger(u'mssqlcli.main') self.set_default_pager(c) self.output_file = None self.multi_line = c['main'].as_bool('multi_line') self.multiline_mode = c['main'].get('multi_line_mode', 'tsql') self.vi_mode = c['main'].as_bool('vi') self.auto_expand = options.auto_vertical_output or c['main']['expand'] == 'auto' self.expanded_output = c['main']['expand'] == 'always' self.prompt_format = options.prompt or c['main'].get('prompt', self.default_prompt) if options.row_limit is not None: self.row_limit = options.row_limit else: self.row_limit = c['main'].as_int('row_limit') self.min_num_menu_lines = c['main'].as_int('min_num_menu_lines') self.multiline_continuation_char = c['main']['multiline_continuation_char'] self.table_format = c['main']['table_format'] self.syntax_style = c['main']['syntax_style'] self.cli_style = c['colors'] self.wider_completion_menu = c['main'].as_bool('wider_completion_menu') self.less_chatty = bool( options.less_chatty) or c['main'].as_bool('less_chatty') self.null_string = c['main'].get('null_string', '<null>') self.on_error = c['main']['on_error'].upper() self.decimal_format = c['data_formats']['decimal'] self.float_format = c['data_formats']['float'] self.now = dt.datetime.today() self.completion_refresher = CompletionRefresher() self.query_history = [] # Initialize completer smart_completion = True if c['main'].get('smart_completion', 'True') == 'True' else False keyword_casing = c['main']['keyword_casing'] self.settings = { 'casing_file': get_casing_file(c), 'generate_casing_file': c['main'].as_bool('generate_casing_file'), 'generate_aliases': c['main'].as_bool('generate_aliases'), 'asterisk_column_order': c['main']['asterisk_column_order'], 'qualify_columns': c['main']['qualify_columns'], 'case_column_headers': c['main'].as_bool('case_column_headers'), 'search_path_filter': c['main'].as_bool('search_path_filter'), 'single_connection': False, 'less_chatty': options.less_chatty, 'keyword_casing': keyword_casing, } self.completer = MssqlCompleter(smart_completion=smart_completion, settings=self.settings) self._completer_lock = threading.Lock() self.eventloop = create_eventloop() self.cli = None self.integrated_auth = options.integrated_auth self.sqltoolsclient = SqlToolsClient(enable_logging=options.enable_sqltoolsservice_logging) self.mssqlcliclient_main = MssqlCliClient(options, self.sqltoolsclient)
def __init__(self, options): # Load config. c = self.config = get_config(options.mssqlclirc_file) self.initialize_logging() self.logger = logging.getLogger(u'mssqlcli.main') self.interactive_mode = options.interactive_mode self.table_format = c['main']['table_format'] self.decimal_format = c['data_formats']['decimal'] self.float_format = c['data_formats']['float'] self.null_string = c['main'].get('null_string', '<null>') self.expanded_output = c['main']['expand'] == 'always' self.integrated_auth = options.integrated_auth self.less_chatty = bool(options.less_chatty) or c['main'].as_bool( 'less_chatty') or self.interactive_mode keyword_casing = c['main']['keyword_casing'] self.settings = { 'casing_file': get_casing_file(c), 'generate_casing_file': c['main'].as_bool('generate_casing_file'), 'generate_aliases': c['main'].as_bool('generate_aliases'), 'asterisk_column_order': c['main']['asterisk_column_order'], 'qualify_columns': c['main']['qualify_columns'], 'case_column_headers': c['main'].as_bool('case_column_headers'), 'search_path_filter': c['main'].as_bool('search_path_filter'), 'single_connection': False, 'less_chatty': self.less_chatty, 'keyword_casing': keyword_casing, } if self.interactive_mode: pager = self.set_default_pager(c) self.prompt_session = None # set auto_expand to false if less is detected with auto expand self.auto_expand = options.auto_vertical_output \ or (c['main']['expand'] == 'auto' and pager != 'less -SRXF') self.multiline = c['main'].as_bool('multi_line') self.multiline_mode = c['main'].get('multi_line_mode', 'tsql') self.vi_mode = c['main'].as_bool('vi') self.prompt_format = options.prompt or c['main'].get( 'prompt', self.default_prompt) if options.row_limit is not None: self.row_limit = options.row_limit else: self.row_limit = c['main'].as_int('row_limit') self.min_num_menu_lines = c['main'].as_int('min_num_menu_lines') self.multiline_continuation_char = c['main'][ 'multiline_continuation_char'] self.syntax_style = c['main']['syntax_style'] self.cli_style = c['colors'] self.output_style = style_factory_output(self.syntax_style, self.cli_style) self.wider_completion_menu = c['main'].as_bool( 'wider_completion_menu') self.on_error = c['main']['on_error'].upper() self.now = dt.datetime.today() self.completion_refresher = CompletionRefresher() self.query_history = [] # Initialize completer smart_completion = c['main'].get('smart_completion', 'True').lower() == 'true' self.completer = MssqlCompleter(smart_completion=smart_completion, settings=self.settings) self._completer_lock = threading.Lock() # input and output file are for non-interactive mode self.input_file = options.input_file self.output_file = options.output_file self.query = options.query self.sqltoolsclient = SqlToolsClient( enable_logging=options.enable_sqltoolsservice_logging) self.mssqlcliclient_main = MssqlCliClient(options, self.sqltoolsclient) # exit and return error if user enters interactive mode with -i or -o arguments enabled if self.interactive_mode and (self.input_file or self.output_file): raise ValueError( "Invalid arguments: -i and -o can only be used in non-interactive " "mode.") # exit and return error if both query text and an input file are specified if self.query and self.input_file: raise ValueError( "Invalid arguments: either query [-Q] or input file [-i] may be " "specified.")