From 023e63e45c5f7ed3231d2c8a2260b59d3e5f8ea9 Mon Sep 17 00:00:00 2001 From: ajspig Date: Mon, 13 Apr 2026 09:39:18 -0400 Subject: [PATCH] feat: make init --yes fall back to existing config --- honcho-cli/src/honcho_cli/commands/setup.py | 27 +++++++++++++-------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/honcho-cli/src/honcho_cli/commands/setup.py b/honcho-cli/src/honcho_cli/commands/setup.py index 64cd3f73..47f2eea7 100644 --- a/honcho-cli/src/honcho_cli/commands/setup.py +++ b/honcho-cli/src/honcho_cli/commands/setup.py @@ -80,24 +80,31 @@ def init( # --- Non-interactive path --- if yes: - if not api_key: - print_error("MISSING_FLAG", "--api-key is required with --yes", {}) + # Fall back to existing config for any values not explicitly provided + existing = CLIConfig.load() + resolved_url = base_url + resolved_key = api_key or existing.api_key + resolved_ws = workspace or existing.workspace_id + resolved_peer = peer or existing.peer_id + + if not resolved_key: + print_error("MISSING_FLAG", "--api-key is required (not found in config or env)", {}) raise typer.Exit(1) - if not workspace: - print_error("MISSING_FLAG", "--workspace is required with --yes", {}) + if not resolved_ws: + print_error("MISSING_FLAG", "--workspace is required (not found in config or env)", {}) raise typer.Exit(1) # Test connection - ok, detail = _test_connection(base_url, api_key) + ok, detail = _test_connection(resolved_url, resolved_key) if not ok: - print_error("CONNECTION_FAILED", f"Cannot reach {base_url}: {detail}", {"base_url": base_url}) + print_error("CONNECTION_FAILED", f"Cannot reach {resolved_url}: {detail}", {"base_url": resolved_url}) raise typer.Exit(1) config = CLIConfig( - base_url=base_url, - api_key=api_key, - workspace_id=workspace, - peer_id=peer or "", + base_url=resolved_url, + api_key=resolved_key, + workspace_id=resolved_ws, + peer_id=resolved_peer, ) config.save() print_result(config.redacted())