Skip to content

Commit 1343081

Browse files
authored
Merge pull request #1735 from dbcli/RW/support-hostname-alternate-argument
Allow `--hostname` as an alias for `--host`
2 parents 0bf4235 + 1ee33e4 commit 1343081

3 files changed

Lines changed: 58 additions & 0 deletions

File tree

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Upcoming (TBD)
44
Features
55
---------
66
* Respond to `-h` alone with the helpdoc.
7+
* Allow `--hostname` as an alias for `--host`.
78

89

910
Bug Fixes

mycli/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,6 +1920,8 @@ class CliArgs:
19201920
)
19211921
host: str | None = clickdc.option(
19221922
'-h',
1923+
'--hostname',
1924+
'host',
19231925
type=str,
19241926
envvar='MYSQL_HOST',
19251927
help='Host address of the database.',

test/pytests/test_main.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,6 +1528,61 @@ def run_query(self, query, new_line=True):
15281528
assert MockMyCli.connect_args['host'] == 'env_host'
15291529

15301530

1531+
def test_hostname_option_alias(monkeypatch):
1532+
class Formatter:
1533+
format_name = None
1534+
1535+
class Logger:
1536+
def debug(self, *args, **args_dict):
1537+
pass
1538+
1539+
def warning(self, *args, **args_dict):
1540+
pass
1541+
1542+
class MockMyCli:
1543+
config = {
1544+
'main': {},
1545+
'alias_dsn': {},
1546+
'connection': {
1547+
'default_keepalive_ticks': 0,
1548+
},
1549+
}
1550+
1551+
def __init__(self, **_args):
1552+
self.logger = Logger()
1553+
self.destructive_warning = False
1554+
self.main_formatter = Formatter()
1555+
self.redirect_formatter = Formatter()
1556+
self.ssl_mode = 'auto'
1557+
self.my_cnf = {'client': {}, 'mysqld': {}}
1558+
self.default_keepalive_ticks = 0
1559+
1560+
def connect(self, **args):
1561+
MockMyCli.connect_args = args
1562+
1563+
def run_query(self, query, new_line=True):
1564+
pass
1565+
1566+
import mycli.main
1567+
1568+
monkeypatch.setattr(mycli.main, 'MyCli', MockMyCli)
1569+
runner = CliRunner()
1570+
1571+
result = runner.invoke(
1572+
mycli.main.click_entrypoint,
1573+
args=[
1574+
'--hostname',
1575+
'alias_host',
1576+
'--port',
1577+
f'{DEFAULT_PORT}',
1578+
'--database',
1579+
'database',
1580+
],
1581+
)
1582+
assert result.exit_code == 0
1583+
assert MockMyCli.connect_args['host'] == 'alias_host'
1584+
1585+
15311586
def test_port_option_and_mysql_tcp_port_envvar(monkeypatch):
15321587
class Formatter:
15331588
format_name = None

0 commit comments

Comments
 (0)