Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unified 'exit' as 'sys.exit' in the code to improve cross platform co… #1187

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading