Skip to content

Commit fd7611a

Browse files
committed
add unsupported and deprecated checkup sections
Let --checkup show config options which are read and ignored, as well as config options which are read, but deprecated.
1 parent 735cef8 commit fd7611a

3 files changed

Lines changed: 65 additions & 13 deletions

File tree

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Features
66
* Options to limit size of LLM prompts; cache LLM prompt data.
77
* Add startup usage tips.
88
* Move `main.ssl_mode` config option to `connection.default_ssl_mode`.
9+
* Add "unsupported" and "deprecated" `--checkup` sections.
910

1011

1112
Bug Fixes

mycli/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ def read_config_files(
8282
files: list[str | IO[str]],
8383
list_values: bool = True,
8484
ignore_package_defaults: bool = False,
85+
ignore_user_options: bool = False,
8586
) -> ConfigObj:
8687
"""Read and merge a list of config files."""
8788

@@ -90,6 +91,9 @@ def read_config_files(
9091
else:
9192
config = create_default_config(list_values=list_values)
9293

94+
if ignore_user_options:
95+
return config
96+
9397
_files = copy(files)
9498
while _files:
9599
_file = _files.pop(0)

mycli/main.py

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,10 @@ def __init__(
142142
# this parallel config exists to
143143
# * compare with my.cnf
144144
# * support the --checkup feature
145+
# todo: after removing my.cnf, create the parallel configs only when --checkup is set
145146
self.config_without_package_defaults = read_config_files(config_files, ignore_package_defaults=True)
147+
# this parallel config exists to compare with my.cnf support the --checkup feature
148+
self.config_without_user_options = read_config_files(config_files, ignore_user_options=True)
146149
self.multi_line = c["main"].as_bool("multi_line")
147150
self.key_bindings = c["main"]["key_bindings"]
148151
special.set_timing_enabled(c["main"].as_bool("timing"))
@@ -2272,28 +2275,72 @@ def read_ssh_config(ssh_config_path: str):
22722275

22732276

22742277
def do_config_checkup(mycli: MyCli) -> None:
2275-
did_output = False
2278+
did_output_missing = False
2279+
did_output_unsupported = False
2280+
did_output_deprecated = False
2281+
2282+
indent = ' '
2283+
transitions = {
2284+
f'{indent}[main]\n{indent}default_character_set': f'{indent}[connection]\n{indent}default_character_set',
2285+
f'{indent}[main]\n{indent}ssl_mode': f'{indent}[connection]\n{indent}default_ssl_mode',
2286+
}
22762287

22772288
if not list(mycli.config.keys()):
22782289
print('\nThe local ~/,myclirc is missing or empty.\n')
2279-
did_output = True
2290+
did_output_missing = True
22802291
else:
2281-
for section_name in mycli.config.keys():
2292+
for section_name in mycli.config:
22822293
if section_name not in mycli.config_without_package_defaults:
2283-
if not did_output:
2284-
print('\nMissing in user ~/.myclirc:\n')
2285-
print(f'The entire section:\n\n [{section_name}]\n')
2286-
did_output = True
2294+
if not did_output_missing:
2295+
print('\n### Missing in user ~/.myclirc:\n')
2296+
print(f'The entire section:\n\n{indent}[{section_name}]\n')
2297+
did_output_missing = True
22872298
continue
22882299
for item_name in mycli.config[section_name]:
22892300
if item_name not in mycli.config_without_package_defaults[section_name]:
2290-
if not did_output:
2291-
print('\nMissing in user ~/.myclirc:\n')
2292-
print(f'The item:\n\n [{section_name}]\n {item_name} =\n')
2293-
did_output = True
2294-
if did_output:
2301+
if not did_output_missing:
2302+
print('\n### Missing in user ~/.myclirc:\n')
2303+
print(f'The item:\n\n{indent}[{section_name}]\n{indent}{item_name} =\n')
2304+
did_output_missing = True
2305+
2306+
for section_name in mycli.config_without_package_defaults:
2307+
if section_name not in mycli.config_without_user_options:
2308+
if not did_output_unsupported:
2309+
print('\n### Unsupported in user ~/.myclirc:\n')
2310+
did_output_unsupported = True
2311+
print(f'The entire section:\n\n{indent}[{section_name}]\n')
2312+
continue
2313+
for item_name in mycli.config_without_package_defaults[section_name]:
2314+
if section_name == 'colors' and item_name.startswith('sql.'):
2315+
# these are commented out in the package myclirc
2316+
continue
2317+
transition_key = f'{indent}[{section_name}]\n{indent}{item_name}'
2318+
if transition_key in transitions:
2319+
continue
2320+
if item_name not in mycli.config_without_user_options[section_name]:
2321+
if not did_output_unsupported:
2322+
print('\n### Unsupported in user ~/.myclirc:\n')
2323+
print(f'The item:\n\n{indent}[{section_name}]\n{indent}{item_name} =\n')
2324+
did_output_unsupported = True
2325+
2326+
for section_name in mycli.config_without_package_defaults:
2327+
if section_name not in mycli.config_without_user_options:
2328+
continue
2329+
for item_name in mycli.config_without_package_defaults[section_name]:
2330+
if section_name == 'colors' and item_name.startswith('sql.'):
2331+
# these are commented out in the package myclirc
2332+
continue
2333+
transition_key = f'{indent}[{section_name}]\n{indent}{item_name}'
2334+
if transition_key in transitions:
2335+
if not did_output_deprecated:
2336+
print('\n### Deprecated in user ~/.myclirc:\n')
2337+
transition_value = transitions[transition_key]
2338+
print(f'It is recommended to transition:\n\n{transition_key}\n\nto\n\n{transition_value}\n')
2339+
did_output_deprecated = True
2340+
2341+
if did_output_missing or did_output_unsupported or did_output_deprecated:
22952342
print(
2296-
'For more info on new features, see the commentary and defaults at:\n\n * https://github.com/dbcli/mycli/blob/main/mycli/myclirc\n'
2343+
'For more info on supported features, see the commentary and defaults at:\n\n * https://github.com/dbcli/mycli/blob/main/mycli/myclirc\n'
22972344
)
22982345
else:
22992346
print('User configuration all up to date!')

0 commit comments

Comments
 (0)