def run(self): """ Spins up CLI. """ # raise error if interactive mode is set to false here if not self.interactive_mode: raise ValueError( "Invalid arguments: 'run' must be used in interactive mode! Please set " "interactive_mode to True.") # exit and return error if user enters interactive mode with -o argument enabled if self.output_file: raise ValueError( "Invalid arguments: -o must be used with interactive mode set to " "false.") history_file = self.config['main']['history_file'] if history_file == 'default': history_file = config_location() + 'history' history = MssqlFileHistory(os.path.expanduser(history_file)) self.refresh_completions(history=history, persist_priorities='none') self.prompt_session = self._build_cli(history) if not self.less_chatty: print('Version: {}'.format(__version__)) print('Mail: [email protected]') print('Home: http://github.com/dbcli/mssql-cli') try: while True: try: text = self.prompt_session.prompt() except KeyboardInterrupt: continue # The reason we check here instead of inside the mssqlcliclient is # because we want to raise the Exit exception which will be # caught by the try/except block that wraps the mssqlcliclient execute # statement. if self.quit_command(text): raise EOFError try: text = self.handle_editor_command(text) except RuntimeError as e: self.logger.error("sql: %r, error: %r", text, e) self.logger.error("traceback: %r", traceback.format_exc()) click.secho(str(e), err=True, fg='red') continue self.execute_query(text) self.now = dt.datetime.today() except EOFError: self.mssqlcliclient_main.shutdown() if not self.less_chatty: print(localized.goodbye())
def run(self): history_file = self.config['main']['history_file'] if history_file == 'default': history_file = config_location() + 'history' history = MssqlFileHistory(os.path.expanduser(history_file)) self.refresh_completions(history=history, persist_priorities='none') self.prompt_session = self._build_cli(history) if not self.less_chatty: print('Version: {}'.format(__version__)) print('Mail: [email protected]') print('Home: http://github.com/dbcli/mssql-cli') try: while True: try: text = self.prompt_session.prompt() except KeyboardInterrupt: continue # The reason we check here instead of inside the mssqlcliclient is # because we want to raise the Exit exception which will be # caught by the try/except block that wraps the mssqlcliclient execute # statement. if self.quit_command(text): raise EOFError try: text = self.handle_editor_command(text) except RuntimeError as e: self.logger.error("sql: %r, error: %r", text, e) self.logger.error("traceback: %r", traceback.format_exc()) click.secho(str(e), err=True, fg='red') continue # Initialize default metaquery in case execution fails query = MetaQuery(query=text, successful=False) query = self.execute_command(text, query) self.now = dt.datetime.today() if not query.contains_secure_statement: # Allow MssqlCompleter to learn user's preferred keywords, etc. with self._completer_lock: self.completer.extend_query_history(text) self.query_history.append(query) except EOFError: self.mssqlcliclient_main.shutdown() if not self.less_chatty: print(localized.goodbye())
def test_product(): original = localized.goodbye() localized.translation(languages=['ko']).install() translated = decode(localized.goodbye()) assert original != translated