Spins up CLI.
(self)
| 393 | click.echo('\n'.join(output)) |
| 394 | |
| 395 | def run(self): |
| 396 | """ Spins up CLI. """ |
| 397 | |
| 398 | # raise error if interactive mode is set to false here |
| 399 | if not self.interactive_mode: |
| 400 | raise ValueError("Invalid arguments: 'run' must be used in interactive mode! Please set " |
| 401 | "interactive_mode to True.") |
| 402 | |
| 403 | # exit and return error if user enters interactive mode with -o argument enabled |
| 404 | if self.output_file: |
| 405 | raise ValueError("Invalid arguments: -o must be used with interactive mode set to " |
| 406 | "false.") |
| 407 | |
| 408 | history_file = self.config['main']['history_file'] |
| 409 | if history_file == 'default': |
| 410 | history_file = config_location() + 'history' |
| 411 | history = MssqlFileHistory(os.path.expanduser(history_file)) |
| 412 | |
| 413 | self.refresh_completions(history=history, |
| 414 | persist_priorities='none') |
| 415 | |
| 416 | self.prompt_session = self._build_cli(history) |
| 417 | |
| 418 | if not self.less_chatty: |
| 419 | print('Version: {}'.format(__version__)) |
| 420 | print('Mail: sqlcli@microsoft.com') |
| 421 | print('Home: http://github.com/dbcli/mssql-cli') |
| 422 | |
| 423 | try: |
| 424 | while True: |
| 425 | try: |
| 426 | text = self.prompt_session.prompt() |
| 427 | except KeyboardInterrupt: |
| 428 | continue |
| 429 | |
| 430 | # The reason we check here instead of inside the mssqlcliclient is |
| 431 | # because we want to raise the Exit exception which will be |
| 432 | # caught by the try/except block that wraps the mssqlcliclient execute |
| 433 | # statement. |
| 434 | if self.quit_command(text): |
| 435 | raise EOFError |
| 436 | |
| 437 | try: |
| 438 | text = self.handle_editor_command(text) |
| 439 | except RuntimeError as e: |
| 440 | self.logger.error("sql: %r, error: %r", text, e) |
| 441 | self.logger.error("traceback: %r", traceback.format_exc()) |
| 442 | click.secho(str(e), err=True, fg='red') |
| 443 | continue |
| 444 | |
| 445 | self.execute_query(text) |
| 446 | self.now = dt.datetime.today() |
| 447 | |
| 448 | except EOFError: |
| 449 | self.mssqlcliclient_main.shutdown() |
| 450 | if not self.less_chatty: |
| 451 | print(localized.goodbye()) |
| 452 |