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)
Features
---------
* Respond to `-h` alone with the helpdoc.
* Allow `--hostname` as an alias for `--host`.


Bug Fixes
Expand Down
2 changes: 2 additions & 0 deletions mycli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1918,6 +1918,8 @@ class CliArgs:
)
host: str | None = clickdc.option(
'-h',
'--hostname',
'host',
type=str,
envvar='MYSQL_HOST',
help='Host address of the database.',
Expand Down
55 changes: 55 additions & 0 deletions test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1485,6 +1485,61 @@ def run_query(self, query, new_line=True):
assert MockMyCli.connect_args['host'] == 'env_host'


def test_hostname_option_alias(monkeypatch):
class Formatter:
format_name = None

class Logger:
def debug(self, *args, **args_dict):
pass

def warning(self, *args, **args_dict):
pass

class MockMyCli:
config = {
'main': {},
'alias_dsn': {},
'connection': {
'default_keepalive_ticks': 0,
},
}

def __init__(self, **_args):
self.logger = Logger()
self.destructive_warning = False
self.main_formatter = Formatter()
self.redirect_formatter = Formatter()
self.ssl_mode = 'auto'
self.my_cnf = {'client': {}, 'mysqld': {}}
self.default_keepalive_ticks = 0

def connect(self, **args):
MockMyCli.connect_args = args

def run_query(self, query, new_line=True):
pass

import mycli.main

monkeypatch.setattr(mycli.main, 'MyCli', MockMyCli)
runner = CliRunner()

result = runner.invoke(
mycli.main.click_entrypoint,
args=[
'--hostname',
'alias_host',
'--port',
f'{DEFAULT_PORT}',
'--database',
'database',
],
)
assert result.exit_code == 0
assert MockMyCli.connect_args['host'] == 'alias_host'


def test_port_option_and_mysql_tcp_port_envvar(monkeypatch):
class Formatter:
format_name = None
Expand Down
Loading