From f6a576f0ec04a9b2fa2982e2e9188d874bbd156c Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 8 Apr 2024 10:07:30 +0200 Subject: Merging upstream version 1.27.2. Signed-off-by: Daniel Baumann --- mycli/main.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'mycli/main.py') diff --git a/mycli/main.py b/mycli/main.py index 208572d..ce4dff7 100755 --- a/mycli/main.py +++ b/mycli/main.py @@ -93,6 +93,7 @@ SUPPORT_INFO = ( class MyCli(object): default_prompt = '\\t \\u@\\h:\\d> ' + default_prompt_splitln = '\\u@\\h\\n(\\t):\\d>' max_len_prompt = 45 defaults_suffix = None @@ -427,6 +428,7 @@ class MyCli(object): port = 3306 if not host or host == 'localhost': socket = ( + socket or cnf['socket'] or cnf['default_socket'] or guess_socket_location() @@ -589,7 +591,7 @@ class MyCli(object): statements = sqlglot.parse(text, read='mysql') except Exception as e: statements = [] - if len(statements) == 1: + if len(statements) == 1 and statements[0]: pretty_text = statements[0].sql(pretty=True, pad=4, dialect='mysql') else: pretty_text = '' @@ -603,7 +605,7 @@ class MyCli(object): statements = sqlglot.parse(text, read='mysql') except Exception as e: statements = [] - if len(statements) == 1: + if len(statements) == 1 and statements[0]: unpretty_text = statements[0].sql(pretty=False, dialect='mysql') else: unpretty_text = '' @@ -643,7 +645,7 @@ class MyCli(object): def get_message(): prompt = self.get_prompt(self.prompt_format) if self.prompt_format == self.default_prompt and len(prompt) > self.max_len_prompt: - prompt = self.get_prompt('\\d> ') + prompt = self.get_prompt(self.default_prompt_splitln) prompt = prompt.replace("\\x1b", "\x1b") return ANSI(prompt) @@ -1038,7 +1040,7 @@ class MyCli(object): for result in results: title, cur, headers, status = result self.formatter.query = query - output = self.format_output(title, cur, headers) + output = self.format_output(title, cur, headers, special.is_expanded_output()) for line in output: click.echo(line, nl=new_line) @@ -1135,6 +1137,9 @@ class MyCli(object): @click.option('--ssl-key', help='X509 key in PEM format.', type=click.Path(exists=True)) @click.option('--ssl-cipher', help='SSL cipher to use.') +@click.option('--tls-version', + type=click.Choice(['TLSv1', 'TLSv1.1', 'TLSv1.2', 'TLSv1.3'], case_sensitive=False), + help='TLS protocol version for secure connection.') @click.option('--ssl-verify-server-cert', is_flag=True, help=('Verify server\'s "Common Name" in its cert against ' 'hostname used when connecting. This option is disabled ' @@ -1186,8 +1191,8 @@ def cli(database, user, host, port, socket, password, dbname, version, verbose, prompt, logfile, defaults_group_suffix, defaults_file, login_path, auto_vertical_output, local_infile, ssl_enable, ssl_ca, ssl_capath, ssl_cert, ssl_key, ssl_cipher, - ssl_verify_server_cert, table, csv, warn, execute, myclirc, dsn, - list_dsn, ssh_user, ssh_host, ssh_port, ssh_password, + tls_version, ssl_verify_server_cert, table, csv, warn, execute, + myclirc, dsn, list_dsn, ssh_user, ssh_host, ssh_port, ssh_password, ssh_key_filename, list_ssh_config, ssh_config_path, ssh_config_host, init_command, charset, password_file): """A MySQL terminal client with auto-completion and syntax highlighting. @@ -1246,6 +1251,7 @@ def cli(database, user, host, port, socket, password, dbname, 'key': ssl_key and os.path.expanduser(ssl_key), 'capath': ssl_capath, 'cipher': ssl_cipher, + 'tls_version': tls_version, 'check_hostname': ssl_verify_server_cert, } @@ -1278,7 +1284,7 @@ def cli(database, user, host, port, socket, password, dbname, uri = urlparse(dsn_uri) if not database: database = uri.path[1:] # ignore the leading fwd slash - if not user: + if not user and uri.username is not None: user = unquote(uri.username) if not password and uri.password is not None: password = unquote(uri.password) @@ -1331,7 +1337,12 @@ def cli(database, user, host, port, socket, password, dbname, try: if csv: mycli.formatter.format_name = 'csv' - elif not table: + if execute.endswith(r'\G'): + execute = execute[:-2] + elif table: + if execute.endswith(r'\G'): + execute = execute[:-2] + else: mycli.formatter.format_name = 'tsv' mycli.run_query(execute) -- cgit v1.2.3