(cli_args: 'CliArgs', client_factory: ClientFactory)
| 92 | |
| 93 | |
| 94 | def run_from_cli_args(cli_args: 'CliArgs', client_factory: ClientFactory) -> None: |
| 95 | from mycli import main as main_module |
| 96 | |
| 97 | cli_verbosity = main_module.preprocess_cli_args(cli_args, is_valid_connection_scheme) |
| 98 | |
| 99 | mycli = client_factory( |
| 100 | prompt=cli_args.prompt, |
| 101 | toolbar_format=cli_args.toolbar, |
| 102 | logfile=cli_args.logfile, |
| 103 | login_path=cli_args.login_path, |
| 104 | auto_vertical_output=cli_args.auto_vertical_output, |
| 105 | warn=cli_args.warn, |
| 106 | myclirc=cli_args.myclirc, |
| 107 | show_warnings=cli_args.show_warnings, |
| 108 | cli_verbosity=cli_verbosity, |
| 109 | ) |
| 110 | |
| 111 | if cli_args.checkup: |
| 112 | main_checkup(mycli) |
| 113 | sys.exit(0) |
| 114 | |
| 115 | if cli_args.csv and cli_args.format not in [None, 'csv']: |
| 116 | click.secho("Conflicting --csv and --format arguments.", err=True, fg="red") |
| 117 | sys.exit(1) |
| 118 | |
| 119 | if cli_args.table and cli_args.format not in [None, 'table']: |
| 120 | click.secho("Conflicting --table and --format arguments.", err=True, fg="red") |
| 121 | sys.exit(1) |
| 122 | |
| 123 | if not cli_args.format: |
| 124 | cli_args.format = 'default' |
| 125 | |
| 126 | if cli_args.csv: |
| 127 | cli_args.format = 'csv' |
| 128 | |
| 129 | if cli_args.table: |
| 130 | cli_args.format = 'table' |
| 131 | |
| 132 | if cli_args.list_dsn: |
| 133 | sys.exit(main_list_dsn(mycli)) |
| 134 | |
| 135 | # Choose which ever one has a valid value. |
| 136 | database = cli_args.dbname or cli_args.database |
| 137 | |
| 138 | dsn_uri = None |
| 139 | |
| 140 | # Treat the database argument as a DSN alias only if it matches a configured alias |
| 141 | # todo why is port tested but not socket? |
| 142 | truthy_password = cli_args.password not in (None, EMPTY_PASSWORD_FLAG_SENTINEL) |
| 143 | if ( |
| 144 | database |
| 145 | and "://" not in database |
| 146 | and not any([ |
| 147 | cli_args.user, |
| 148 | truthy_password, |
| 149 | cli_args.host, |
| 150 | cli_args.port, |
| 151 | cli_args.login_path, |
no test coverage detected