Skip to content

Commit ed86161

Browse files
authored
Merge pull request #1590 from dbcli/RW/accept-character-set-cli-argument
Make `--character-set` an alias for `--charset` at the CLI
2 parents 50135d9 + defc199 commit ed86161

9 files changed

Lines changed: 30 additions & 29 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
* Let the `--dsn` argument accept literal DSNs as well as aliases.
7+
* Accept `--character-set` as an alias for `--charset` at the CLI.
78

89

910
Bug Fixes

mycli/TIPS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ the --throttle option helps slow down queries in batch mode!
1616

1717
the --password-file option can be used with a FIFO to avoid saving creds to a file!
1818

19-
the --charset option sets the character set for a single session!
19+
the --character-set option sets the character set for a single session!
2020

2121
the --unbuffered flag can save memory when in batch mode!
2222

mycli/completion_refresher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def _bg_refresh(
6565
e.host,
6666
e.port,
6767
e.socket,
68-
e.charset,
68+
e.character_set,
6969
e.local_infile,
7070
e.ssl,
7171
e.ssh_user,

mycli/main.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ def connect(
532532
host: str | None = "",
533533
port: str | int | None = "",
534534
socket: str | None = "",
535-
charset: str | None = "",
535+
character_set: str | None = "",
536536
local_infile: bool = False,
537537
ssl: dict[str, Any] | None = None,
538538
ssh_user: str | None = "",
@@ -590,17 +590,17 @@ def connect(
590590
# default_character_set doesn't check in self.config_without_package_defaults, because the
591591
# option already existed before the my.cnf deprecation. For the same reason,
592592
# default_character_set can be in [connection] or [main].
593-
if not charset:
593+
if not character_set:
594594
if 'default_character_set' in self.config['connection']:
595-
charset = self.config['connection']['default_character_set']
595+
character_set = self.config['connection']['default_character_set']
596596
elif 'default_character_set' in self.config['main']:
597-
charset = self.config['main']['default_character_set']
597+
character_set = self.config['main']['default_character_set']
598598
elif 'default_character_set' in cnf:
599-
charset = cnf['default_character_set']
599+
character_set = cnf['default_character_set']
600600
elif 'default-character-set' in cnf:
601-
charset = cnf['default-character-set']
602-
if not charset:
603-
charset = 'utf8mb4'
601+
character_set = cnf['default-character-set']
602+
if not character_set:
603+
character_set = 'utf8mb4'
604604

605605
# Favor whichever local_infile option is set.
606606
use_local_infile = False
@@ -683,7 +683,7 @@ def _connect() -> None:
683683
host,
684684
int_port,
685685
socket,
686-
charset,
686+
character_set,
687687
use_local_infile,
688688
ssl_config_or_none,
689689
ssh_user,
@@ -704,7 +704,7 @@ def _connect() -> None:
704704
host,
705705
int_port,
706706
socket,
707-
charset,
707+
character_set,
708708
use_local_infile,
709709
None,
710710
ssh_user,
@@ -1712,7 +1712,7 @@ def get_last_query(self) -> str | None:
17121712
@click.option(
17131713
"--unbuffered", is_flag=True, help="Instead of copying every row of data into a buffer, fetch rows as needed, to save memory."
17141714
)
1715-
@click.option("--charset", type=str, help="Character set for MySQL session.")
1715+
@click.option("--character-set", "--charset", type=str, help="Character set for MySQL session.")
17161716
@click.option(
17171717
"--password-file", type=click.Path(), help="File or FIFO path containing the password to connect to the db if not specified otherwise."
17181718
)
@@ -1777,7 +1777,7 @@ def cli(
17771777
ssh_warning_off: bool | None,
17781778
init_command: str | None,
17791779
unbuffered: bool | None,
1780-
charset: str | None,
1780+
character_set: str | None,
17811781
password_file: str | None,
17821782
noninteractive: bool,
17831783
batch_format: str | None,
@@ -2165,7 +2165,7 @@ def get_password_from_file(password_file: str | None) -> str | None:
21652165
ssh_key_filename=ssh_key_filename,
21662166
init_command=combined_init_cmd,
21672167
unbuffered=unbuffered,
2168-
charset=charset,
2168+
character_set=character_set,
21692169
use_keyring=use_keyring,
21702170
reset_keyring=reset_keyring,
21712171
)

mycli/myclirc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ use_keyring = False
153153

154154
[connection]
155155

156-
# character set for connections without --charset being set
156+
# character set for connections without --character-set being set
157157
default_character_set = utf8mb4
158158

159159
# whether to enable LOAD DATA LOCAL INFILE for connections without --local-infile being set

mycli/sqlexecute.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def __init__(
156156
host: str | None,
157157
port: int | None,
158158
socket: str | None,
159-
charset: str | None,
159+
character_set: str | None,
160160
local_infile: bool | None,
161161
ssl: dict[str, Any] | None,
162162
ssh_user: str | None,
@@ -173,7 +173,7 @@ def __init__(
173173
self.host = host
174174
self.port = port
175175
self.socket = socket
176-
self.charset = charset
176+
self.character_set = character_set
177177
self.local_infile = local_infile
178178
self.ssl = ssl
179179
self.server_info: ServerInfo | None = None
@@ -196,7 +196,7 @@ def connect(
196196
host: str | None = None,
197197
port: int | None = None,
198198
socket: str | None = None,
199-
charset: str | None = None,
199+
character_set: str | None = None,
200200
local_infile: bool | None = None,
201201
ssl: dict[str, Any] | None = None,
202202
ssh_host: str | None = None,
@@ -213,7 +213,7 @@ def connect(
213213
host = host if host is not None else self.host
214214
port = port if port is not None else self.port
215215
socket = socket if socket is not None else self.socket
216-
charset = charset if charset is not None else self.charset
216+
character_set = character_set if character_set is not None else self.character_set
217217
local_infile = local_infile if local_infile is not None else self.local_infile
218218
ssl = ssl if ssl is not None else self.ssl
219219
ssh_user = ssh_user if ssh_user is not None else self.ssh_user
@@ -230,7 +230,7 @@ def connect(
230230
"\thost: %r"
231231
"\tport: %r"
232232
"\tsocket: %r"
233-
"\tcharset: %r"
233+
"\tcharacter_set: %r"
234234
"\tlocal_infile: %r"
235235
"\tssl: %r"
236236
"\tssh_user: %r"
@@ -245,7 +245,7 @@ def connect(
245245
host,
246246
port,
247247
socket,
248-
charset,
248+
character_set,
249249
local_infile,
250250
ssl,
251251
ssh_user,
@@ -285,7 +285,7 @@ def connect(
285285
port=port or 0,
286286
unix_socket=socket,
287287
use_unicode=True,
288-
charset=charset or '',
288+
charset=character_set or '',
289289
autocommit=True,
290290
client_flag=client_flag,
291291
local_infile=local_infile or False,
@@ -331,7 +331,7 @@ def connect(
331331
self.host = host
332332
self.port = port
333333
self.socket = socket
334-
self.charset = charset
334+
self.character_set = character_set
335335
self.ssl = ssl
336336
self.init_command = init_command
337337
self.unbuffered = unbuffered

test/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pytest
44

55
import mycli.sqlexecute
6-
from test.utils import CHARSET, DATABASE, HOST, PASSWORD, PORT, SSH_HOST, SSH_PORT, SSH_USER, USER, create_db, db_connection
6+
from test.utils import CHARACTER_SET, DATABASE, HOST, PASSWORD, PORT, SSH_HOST, SSH_PORT, SSH_USER, USER, create_db, db_connection
77

88

99
@pytest.fixture(scope="function")
@@ -30,7 +30,7 @@ def executor(connection):
3030
password=PASSWORD,
3131
port=PORT,
3232
socket=None,
33-
charset=CHARSET,
33+
character_set=CHARACTER_SET,
3434
local_infile=False,
3535
ssl=None,
3636
ssh_user=SSH_USER,

test/myclirc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ use_keyring = False
151151

152152
[connection]
153153

154-
# character set for connections without --charset being set
154+
# character set for connections without --character-set being set
155155
default_character_set = utf8mb4
156156

157157
# whether to enable LOAD DATA LOCAL INFILE for connections without --local-infile being set

test/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
USER = os.getenv("PYTEST_USER", "root")
1717
HOST = os.getenv("PYTEST_HOST", "localhost")
1818
PORT = int(os.getenv("PYTEST_PORT", "3306"))
19-
CHARSET = os.getenv("PYTEST_CHARSET", "utf8mb4")
19+
CHARACTER_SET = os.getenv("PYTEST_CHARSET", "utf8mb4")
2020
SSH_USER = os.getenv("PYTEST_SSH_USER", None)
2121
SSH_HOST = os.getenv("PYTEST_SSH_HOST", None)
2222
SSH_PORT = int(os.getenv("PYTEST_SSH_PORT", "22"))
2323

2424

2525
def db_connection(dbname=None):
26-
conn = pymysql.connect(user=USER, host=HOST, port=PORT, database=dbname, password=PASSWORD, charset=CHARSET, local_infile=False)
26+
conn = pymysql.connect(user=USER, host=HOST, port=PORT, database=dbname, password=PASSWORD, charset=CHARACTER_SET, local_infile=False)
2727
conn.autocommit = True
2828
return conn
2929

0 commit comments

Comments
 (0)