Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Upcoming (TBD)
Internal
---------
* Require `sqlglot` 30.x.
* Handle Click exceptions by hand.


1.65.0 (2026/03/16)
Expand Down
30 changes: 28 additions & 2 deletions mycli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2021,7 +2021,7 @@ def get_last_query(self) -> str | None:
)
@click.option("--checkup", is_flag=True, help="Run a checkup on your config file.")
@click.pass_context
def cli(
def click_entrypoint(
ctx: click.Context,
database: str | None,
user: str | None,
Expand Down Expand Up @@ -2702,5 +2702,31 @@ def read_ssh_config(ssh_config_path: str):
return ssh_config


def main() -> int | None:
try:
result = click_entrypoint.main(
sys.argv[1:],
standalone_mode=False, # disable builtin exception handling
prog_name='mycli',
)
except click.Abort:
print('Aborted!', file=sys.stderr)
sys.exit(1)
except BrokenPipeError:
sys.exit(1)
except click.ClickException as e:
e.show()
if hasattr(e, 'exit_code'):
sys.exit(e.exit_code)
else:
sys.exit(2)
if result is None:
return 0
elif isinstance(result, int):
return result
else:
return 1


if __name__ == "__main__":
cli()
sys.exit(main())
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ dev = [
]

[project.scripts]
mycli = "mycli.main:cli"
mycli = "mycli.main:main"

[tool.setuptools.package-data]
mycli = ["myclirc", "AUTHORS", "SPONSORS", "TIPS"]
Expand Down
2 changes: 1 addition & 1 deletion test/features/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def before_all(context):
"user": context.config.userdata.get("my_test_user", os.getenv("PYTEST_USER", DEFAULT_USER)),
"pass": context.config.userdata.get("my_test_pass", os.getenv("PYTEST_PASSWORD", None)),
"cli_command": context.config.userdata.get("my_cli_command", None)
or sys.executable + ' -c "import coverage ; coverage.process_startup(); import mycli.main; mycli.main.cli()"',
or sys.executable + ' -c "import coverage ; coverage.process_startup(); import mycli.main; mycli.main.click_entrypoint()"',
"dbname": db_name,
"dbname_tmp": db_name_full + "_tmp",
"vi": vi,
Expand Down
2 changes: 1 addition & 1 deletion test/features/steps/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def add_arg(name, key, value):
try:
cli_cmd = context.conf["cli_command"]
except KeyError:
cli_cmd = f'{sys.executable} -c "import coverage ; coverage.process_startup(); import mycli.main; mycli.main.cli()"'
cli_cmd = f'{sys.executable} -c "import coverage ; coverage.process_startup(); import mycli.main; mycli.main.click_entrypoint()"'

cmd_parts = [cli_cmd] + rendered_args
cmd = " ".join(cmd_parts)
Expand Down
Loading
Loading