@@ -1679,9 +1679,11 @@ def get_last_query(self) -> str | None:
16791679)
16801680@click .version_option (__version__ , "-V" , "--version" , help = "Output mycli's version." )
16811681@click .option ("-v" , "--verbose" , is_flag = True , help = "Verbose output." )
1682- @click .option ("-D" , "--database" , "dbname" , help = "Database to use." )
1683- @click .option ("-d" , "--dsn" , default = "" , envvar = "DSN" , help = "Use DSN configured into the [alias_dsn] section of myclirc file." )
1684- @click .option ("--list-dsn" , "list_dsn" , is_flag = True , help = "list of DSN configured into the [alias_dsn] section of myclirc file." )
1682+ @click .option ("-D" , "--database" , "dbname" , help = "Database or DSN to use for the connection." )
1683+ @click .option ("-d" , "--dsn" , 'dsn_alias' , default = "" , envvar = "DSN" , help = "DSN alias configured in the ~/.myclirc file, or a full DSN." )
1684+ @click .option (
1685+ "--list-dsn" , "list_dsn" , is_flag = True , help = "list of DSN aliases configured in the [alias_dsn] section of the ~/.myclirc file."
1686+ )
16851687@click .option ("--list-ssh-config" , "list_ssh_config" , is_flag = True , help = "list ssh configurations in the ssh config (requires paramiko)." )
16861688@click .option ("--ssh-warning-off" , is_flag = True , help = "Suppress the SSH deprecation notice." )
16871689@click .option ("-R" , "--prompt" , "prompt" , help = f'Prompt format (Default: "{ MyCli .default_prompt } ").' )
@@ -1762,7 +1764,7 @@ def cli(
17621764 warn : bool | None ,
17631765 execute : str | None ,
17641766 myclirc : str ,
1765- dsn : str ,
1767+ dsn_alias : str ,
17661768 list_dsn : str | None ,
17671769 ssh_user : str | None ,
17681770 ssh_host : str | None ,
@@ -1928,23 +1930,27 @@ def get_password_from_file(password_file: str | None) -> str | None:
19281930 and not any ([user , password , host , port , login_path ])
19291931 and database in mycli .config .get ("alias_dsn" , {})
19301932 ):
1931- dsn , database = database , ""
1933+ dsn_alias , database = database , ""
19321934
19331935 if database and "://" in database :
19341936 dsn_uri , database = database , ""
19351937
1936- if dsn :
1938+ if dsn_alias :
19371939 try :
1938- dsn_uri = mycli .config ["alias_dsn" ][dsn ]
1940+ dsn_uri = mycli .config ["alias_dsn" ][dsn_alias ]
19391941 except KeyError :
1940- click .secho (
1941- "Could not find the specified DSN in the config file. Please check the \" [alias_dsn]\" section in your myclirc." ,
1942- err = True ,
1943- fg = "red" ,
1944- )
1945- sys .exit (1 )
1942+ is_valid_scheme , scheme = is_valid_connection_scheme (dsn_alias )
1943+ if is_valid_scheme :
1944+ dsn_uri = dsn_alias
1945+ else :
1946+ click .secho (
1947+ "Could not find the specified DSN in the config file. Please check the \" [alias_dsn]\" section in your myclirc." ,
1948+ err = True ,
1949+ fg = "red" ,
1950+ )
1951+ sys .exit (1 )
19461952 else :
1947- mycli .dsn_alias = dsn
1953+ mycli .dsn_alias = dsn_alias
19481954
19491955 if dsn_uri :
19501956 uri = urlparse (dsn_uri )
@@ -2039,10 +2045,10 @@ def get_password_from_file(password_file: str | None) -> str | None:
20392045 elif val :
20402046 init_cmds .append (val )
20412047 # 2) DSN-specific init-commands
2042- if dsn :
2048+ if dsn_alias :
20432049 alias_section = mycli .config .get ("alias_dsn.init-commands" , {})
2044- if dsn in alias_section :
2045- val = alias_section .get (dsn )
2050+ if dsn_alias in alias_section :
2051+ val = alias_section .get (dsn_alias )
20462052 if isinstance (val , (list , tuple )):
20472053 init_cmds .extend (val )
20482054 elif val :
0 commit comments