77from typing import IO , Literal
88
99from cli_helpers .tabular_output import TabularOutputFormatter
10+ from configobj import ConfigObj
1011from prompt_toolkit .formatted_text import to_formatted_text
1112from prompt_toolkit .shortcuts import PromptSession
1213import sqlparse
1516 AppStateMixin ,
1617 configure_prompt_state ,
1718 destructive_keywords_from_config ,
18- ensure_my_cnf_sections ,
1919 llm_prompt_truncation ,
2020 normalize_ssl_mode ,
2121)
2424from mycli .client_query import ClientQueryMixin
2525from mycli .clistyle import style_factory_helpers , style_factory_ptoolkit
2626from mycli .completion_refresher import CompletionRefresher
27- from mycli .config import get_mylogin_cnf_path , open_mylogin_cnf , read_config_files , write_default_config
27+ from mycli .config import (
28+ get_mylogin_cnf_path ,
29+ open_mylogin_cnf ,
30+ read_config_file ,
31+ read_config_files ,
32+ write_default_config ,
33+ )
2834from mycli .constants import DEFAULT_PROMPT
2935from mycli .main_modes import repl as repl_package
3036from mycli .output import OutputMixin
@@ -44,19 +50,10 @@ class MyCli(AppStateMixin, OutputMixin, ClientCommandsMixin, ClientConnectionMix
4450 default_prompt = DEFAULT_PROMPT
4551 default_prompt_splitln = "\\ u@\\ h\\ n(\\ t):\\ d>"
4652 max_len_prompt = 45
47- defaults_suffix = None
4853 prompt_lines : int
4954 sqlexecute : SQLExecute | None
5055 numeric_alignment : str
5156
52- # In order of being loaded. Files lower in list override earlier ones.
53- cnf_files : list [str | IO [str ]] = [
54- "/etc/my.cnf" ,
55- "/etc/mysql/my.cnf" ,
56- "/usr/local/etc/my.cnf" ,
57- os .path .expanduser ("~/.my.cnf" ),
58- ]
59-
6057 # check XDG_CONFIG_HOME exists and not an empty string
6158 xdg_config_home = os .environ .get ("XDG_CONFIG_HOME" , "~/.config" )
6259 system_config_files : list [str | IO [str ]] = [
@@ -72,8 +69,6 @@ def __init__(
7269 prompt : str | None = None ,
7370 toolbar_format : str | None = None ,
7471 logfile : TextIOWrapper | Literal [False ] | None = None ,
75- defaults_suffix : str | None = None ,
76- defaults_file : str | None = None ,
7772 login_path : str | None = None ,
7873 auto_vertical_output : bool = False ,
7974 warn : bool | None = None ,
@@ -83,7 +78,6 @@ def __init__(
8378 ) -> None :
8479 self .sqlexecute = sqlexecute
8580 self .logfile = logfile
86- self .defaults_suffix = defaults_suffix
8781 self .login_path = login_path
8882 self .toolbar_error_message : str | None = None
8983 self .prompt_session : PromptSession | None = None
@@ -92,23 +86,13 @@ def __init__(
9286 self .sandbox_mode : bool = False
9387 self .checkpoint : IO | None = None
9488
95- # self.cnf_files is a class variable that stores the list of mysql
96- # config files to read in at launch.
97- # If defaults_file is specified then override the class variable with
98- # defaults_file.
99- if defaults_file :
100- self .cnf_files = [defaults_file ]
101-
10289 # Load config.
10390 config_files : list [str | IO [str ]] = self .system_config_files + [myclirc ] + [self .pwd_config_file ]
10491
10592 c = self .config = read_config_files (config_files )
106- # this parallel config exists to
107- # * compare with my.cnf
108- # * support the --checkup feature
109- # todo: after removing my.cnf, create the parallel configs only when --checkup is set
93+ # only needed in --checkup mode. todo: only load when needed
11094 self .config_without_package_defaults = read_config_files (config_files , ignore_package_defaults = True )
111- # this parallel config exists to compare with my.cnf support the --checkup feature
95+ # only needed in --checkup mode. todo: only load when needed
11296 self .config_without_user_options = read_config_files (config_files , ignore_user_options = True )
11397 self .multi_line = c ["main" ].as_bool ("multi_line" )
11498 self .key_bindings = c ["main" ]["key_bindings" ]
@@ -201,20 +185,16 @@ def __init__(
201185 self .register_special_commands ()
202186
203187 # Load .mylogin.cnf if it exists.
204- mylogin_cnf_path = get_mylogin_cnf_path ()
205- if mylogin_cnf_path :
206- mylogin_cnf = open_mylogin_cnf (mylogin_cnf_path )
207- if mylogin_cnf_path and mylogin_cnf :
208- # .mylogin.cnf gets read last, even if defaults_file is specified.
209- self .cnf_files .append (mylogin_cnf )
210- elif mylogin_cnf_path and not mylogin_cnf :
211- # There was an error reading the login path file.
188+ self .mylogin_cnf = ConfigObj ()
189+ mylogin_cnf_h = None
190+ if mylogin_cnf_path := get_mylogin_cnf_path ():
191+ mylogin_cnf_h = open_mylogin_cnf (mylogin_cnf_path )
192+ if mylogin_cnf_h :
193+ self .mylogin_cnf = read_config_file (mylogin_cnf_h , list_values = False ) or ConfigObj ()
194+ else :
212195 print ("Error: Unable to read login path file." )
213196
214- self .my_cnf = read_config_files (self .cnf_files , list_values = False )
215- ensure_my_cnf_sections (self .my_cnf )
216- prompt_cnf = self .read_my_cnf (self .my_cnf , ["prompt" ])["prompt" ]
217- configure_prompt_state (self , c , prompt , prompt_cnf , toolbar_format )
197+ configure_prompt_state (self , c , prompt , toolbar_format )
218198 self .prompt_session = None
219199 self .destructive_keywords = destructive_keywords_from_config (c )
220200 special .set_destructive_keywords (self .destructive_keywords )
0 commit comments