77
88from o2switch_cli .cli .helpers import run_guarded
99from o2switch_cli .cli .ui import TerminalUI
10- from o2switch_cli .config .settings import AppSettings , default_audit_log_path , settings_summary , write_env_file
10+ from o2switch_cli .config .settings import AppSettings , default_audit_log_path , find_env_file , global_config_path , settings_summary , write_env_file
1111from o2switch_cli .core .errors import ValidationAppError
1212
1313app = typer .Typer (help = "Inspect active configuration and API reachability." , rich_markup_mode = "rich" )
1717def show_config (ctx : typer .Context ) -> None :
1818 def action (app_context ):
1919 ui = TerminalUI (app_context .console , app_context .output_format )
20- ui .print_mapping ("Active Configuration" , settings_summary (app_context .settings ))
20+ summary = settings_summary (app_context .settings )
21+ summary ["config_file" ] = find_env_file () or "(none found)"
22+ ui .print_mapping ("Active Configuration" , summary )
23+
24+ run_guarded (ctx , action )
25+
26+
27+ @app .command ("path" )
28+ def show_path (ctx : typer .Context ) -> None :
29+ """Show configuration file paths."""
30+ def action (app_context ):
31+ ui = TerminalUI (app_context .console , app_context .output_format )
32+ ui .print_mapping (
33+ "Config Paths" ,
34+ {
35+ "active" : find_env_file () or "(none)" ,
36+ "global" : str (global_config_path ()),
37+ "local" : str (Path (".env" ).resolve ()),
38+ },
39+ )
2140
2241 run_guarded (ctx , action )
2342
@@ -42,7 +61,7 @@ def action(app_context):
4261@app .command ("init" )
4362def init_config (
4463 ctx : typer .Context ,
45- path : Path = typer .Option (Path ( ".env" ) , "--path" , help = "Write credentials and defaults to this dotenv file." ),
64+ path : Path | None = typer .Option (None , "--path" , help = "Write credentials to this file. Defaults to global config ." ),
4665 cpanel_host : str | None = typer .Option (None , "--cpanel-host" , help = "cPanel host, for example saule.o2switch.net." ),
4766 cpanel_user : str | None = typer .Option (None , "--cpanel-user" , help = "cPanel username." ),
4867 cpanel_token : str | None = typer .Option (None , "--cpanel-token" , help = "cPanel API token." ),
@@ -61,7 +80,7 @@ def init_config(
6180 def action (app_context ):
6281 ui = TerminalUI (app_context .console , app_context .output_format )
6382 current = app_context .settings
64- target = path .expanduser ().resolve ()
83+ target = ( path or global_config_path ()) .expanduser ().resolve ()
6584
6685 if target .exists () and not force and not non_interactive :
6786 if not ui .confirm (f"{ target } already exists. Overwrite it?" ):
0 commit comments