Skip to content

Commit

Permalink
Unified 'exit' as 'sys.exit' in the code to improve cross platform co…
Browse files Browse the repository at this point in the history
…mpatibility

Unified 'exit' as 'sys.exit' in the code to improve cross platform compatibility
  • Loading branch information
fcwys authored Jan 8, 2025
1 parent 8d3dbf3 commit 7159cd1
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions mycli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,14 +524,14 @@ def _connect():
port = int(port)
except ValueError:
self.echo("Error: Invalid port number: '{0}'.".format(port), err=True, fg="red")
exit(1)
sys.exit(1)

_connect()
except Exception as e: # Connecting to a database could fail.
self.logger.debug("Database connection failed: %r.", e)
self.logger.error("traceback: %r", traceback.format_exc())
self.echo(str(e), err=True, fg="red")
exit(1)
sys.exit(1)

def get_password_from_file(self, password_file):
password_from_file = None
Expand Down Expand Up @@ -1224,10 +1224,10 @@ def cli(
alias_dsn = mycli.config["alias_dsn"]
except KeyError:
click.secho("Invalid DSNs found in the config file. " 'Please check the "[alias_dsn]" section in myclirc.', err=True, fg="red")
exit(1)
sys.exit(1)
except Exception as e:
click.secho(str(e), err=True, fg="red")
exit(1)
sys.exit(1)
for alias, value in alias_dsn.items():
if verbose:
click.secho("{} : {}".format(alias, value))
Expand Down Expand Up @@ -1279,7 +1279,7 @@ def cli(
err=True,
fg="red",
)
exit(1)
sys.exit(1)
else:
mycli.dsn_alias = dsn

Expand Down Expand Up @@ -1342,10 +1342,10 @@ def cli(
mycli.formatter.format_name = "tsv"

mycli.run_query(execute)
exit(0)
sys.exit(0)
except Exception as e:
click.secho(str(e), err=True, fg="red")
exit(1)
sys.exit(1)

if sys.stdin.isatty():
mycli.run_cli()
Expand All @@ -1357,7 +1357,7 @@ def cli(
click.secho("Failed! Ran out of memory.", err=True, fg="red")
click.secho("You might want to try the official mysql client.", err=True, fg="red")
click.secho("Sorry... :(", err=True, fg="red")
exit(1)
sys.exit(1)

if mycli.destructive_warning and is_destructive(stdin_text):
try:
Expand All @@ -1366,7 +1366,7 @@ def cli(
except (IOError, OSError):
mycli.logger.warning("Unable to open TTY as stdin.")
if not warn_confirmed:
exit(0)
sys.exit(0)

try:
new_line = True
Expand All @@ -1377,10 +1377,10 @@ def cli(
mycli.formatter.format_name = "tsv"

mycli.run_query(stdin_text, new_line=new_line)
exit(0)
sys.exit(0)
except Exception as e:
click.secho(str(e), err=True, fg="red")
exit(1)
sys.exit(1)


def need_completion_refresh(queries):
Expand Down

0 comments on commit 7159cd1

Please sign in to comment.