feat: add --refresh flag to onboard command for non-interactive config updates
This commit is contained in:
committed by
Xubin Ren
parent
ea7f4679f1
commit
f074aa7d80
@@ -597,6 +597,11 @@ def onboard(
|
|||||||
workspace: str | None = typer.Option(None, "--workspace", "-w", help="Workspace directory"),
|
workspace: str | None = typer.Option(None, "--workspace", "-w", help="Workspace directory"),
|
||||||
config: str | None = typer.Option(None, "--config", "-c", help="Path to config file"),
|
config: str | None = typer.Option(None, "--config", "-c", help="Path to config file"),
|
||||||
wizard: bool = typer.Option(False, "--wizard", help="Use interactive wizard"),
|
wizard: bool = typer.Option(False, "--wizard", help="Use interactive wizard"),
|
||||||
|
refresh: bool = typer.Option(
|
||||||
|
False,
|
||||||
|
"--refresh",
|
||||||
|
help="Refresh config, preserving existing settings without prompting",
|
||||||
|
),
|
||||||
):
|
):
|
||||||
"""Initialize nanobot configuration and workspace."""
|
"""Initialize nanobot configuration and workspace."""
|
||||||
from nanobot.config.loader import get_config_path, load_config, save_config, set_config_path
|
from nanobot.config.loader import get_config_path, load_config, save_config, set_config_path
|
||||||
@@ -618,6 +623,12 @@ def onboard(
|
|||||||
if config_path.exists():
|
if config_path.exists():
|
||||||
if wizard:
|
if wizard:
|
||||||
config = _apply_workspace_override(load_config(config_path))
|
config = _apply_workspace_override(load_config(config_path))
|
||||||
|
elif refresh:
|
||||||
|
config = _apply_workspace_override(load_config(config_path))
|
||||||
|
save_config(config, config_path)
|
||||||
|
console.print(
|
||||||
|
f"[green]✓[/green] Config refreshed at {config_path} (existing values preserved)"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
console.print(f"[yellow]Config already exists at {config_path}[/yellow]")
|
console.print(f"[yellow]Config already exists at {config_path}[/yellow]")
|
||||||
console.print(
|
console.print(
|
||||||
|
|||||||
@@ -218,6 +218,20 @@ def test_onboard_existing_config_refresh(mock_paths):
|
|||||||
assert (workspace_dir / "AGENTS.md").exists()
|
assert (workspace_dir / "AGENTS.md").exists()
|
||||||
|
|
||||||
|
|
||||||
|
def test_onboard_existing_config_refresh_non_interactive(mock_paths):
|
||||||
|
"""Config exists, user specifies --refresh — should refresh non-interactively (no prompt)."""
|
||||||
|
config_file, workspace_dir, _ = mock_paths
|
||||||
|
config_file.write_text('{"existing": true}')
|
||||||
|
|
||||||
|
result = runner.invoke(app, ["onboard", "--refresh"])
|
||||||
|
|
||||||
|
assert result.exit_code == 0
|
||||||
|
assert "Config already exists" not in result.stdout
|
||||||
|
assert "existing values preserved" in result.stdout
|
||||||
|
assert workspace_dir.exists()
|
||||||
|
assert (workspace_dir / "AGENTS.md").exists()
|
||||||
|
|
||||||
|
|
||||||
def test_onboard_existing_config_overwrite(mock_paths):
|
def test_onboard_existing_config_overwrite(mock_paths):
|
||||||
"""Config exists, user confirms overwrite — should reset to defaults."""
|
"""Config exists, user confirms overwrite — should reset to defaults."""
|
||||||
config_file, workspace_dir, _ = mock_paths
|
config_file, workspace_dir, _ = mock_paths
|
||||||
@@ -261,6 +275,7 @@ def test_onboard_help_shows_workspace_and_config_options():
|
|||||||
assert "--config" in stripped_output
|
assert "--config" in stripped_output
|
||||||
assert "-c" in stripped_output
|
assert "-c" in stripped_output
|
||||||
assert "--wizard" in stripped_output
|
assert "--wizard" in stripped_output
|
||||||
|
assert "--refresh" in stripped_output
|
||||||
assert "--dir" not in stripped_output
|
assert "--dir" not in stripped_output
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user