(options)
| 30 | |
| 31 | |
| 32 | def run_cli_with(options): |
| 33 | |
| 34 | if create_config_dir_for_first_use(): |
| 35 | display_telemetry_message() |
| 36 | |
| 37 | display_version_message(options) |
| 38 | |
| 39 | configure_and_update_options(options) |
| 40 | |
| 41 | # Importing MssqlCli creates a config dir by default. |
| 42 | # Moved import here so we can create the config dir for first use prior. |
| 43 | # pylint: disable=import-outside-toplevel |
| 44 | from mssqlcli.mssql_cli import MssqlCli |
| 45 | |
| 46 | # set interactive mode to false if -Q or -i is specified |
| 47 | if options.query or options.input_file: |
| 48 | options.interactive_mode = False |
| 49 | |
| 50 | mssqlcli = MssqlCli(options) |
| 51 | try: |
| 52 | mssqlcli.connect_to_database() |
| 53 | telemetry_session.set_server_information(mssqlcli.mssqlcliclient_main) |
| 54 | |
| 55 | if mssqlcli.interactive_mode: |
| 56 | mssqlcli.run() |
| 57 | else: |
| 58 | text = options.query |
| 59 | if options.input_file: |
| 60 | # get query text from input file |
| 61 | try: |
| 62 | if six.PY2: |
| 63 | with io.open(options.input_file, 'r', encoding='utf-8') as f: |
| 64 | text = f.read() |
| 65 | else: |
| 66 | with open(options.input_file, 'r', encoding='utf-8') as f: |
| 67 | text = f.read() |
| 68 | except OSError as e: |
| 69 | click.secho(str(e), err=True, fg='red') |
| 70 | sys.exit(1) |
| 71 | mssqlcli.execute_query(text) |
| 72 | finally: |
| 73 | mssqlcli.shutdown() |
| 74 | |
| 75 | |
| 76 | def configure_and_update_options(options): |
no test coverage detected