forked from cleveragents/cleveragents-core
fix(cli): add --yes flag to agents init for non-interactive setup
Added --yes/-y flag to the agents init CLI command to support non-interactive initialization as specified in the documentation. When --yes is passed, all interactive prompts are skipped and default values are applied. The command produces the expected initialization summary output including data directory, config file, database, and created directories. The flag was added to both the top-level "agents init" command in main.py and the "agents project init" subcommand in project.py. Both delegate to the shared init_command() function which now accepts a yes parameter and produces spec-aligned Rich panel output (Data Dir, Config, Database, Directories) with the "Initialized (non-interactive)" status message when yes=True. When yes=False (default), existing interactive behavior is preserved unchanged. ISSUES CLOSED: #522
This commit is contained in:
@@ -179,6 +179,7 @@ def init_command(
|
||||
force: bool = False,
|
||||
create_ignore_file: bool = False,
|
||||
default_filters: bool = False,
|
||||
yes: bool = False,
|
||||
) -> None:
|
||||
"""Programmatic interface for initializing a new CleverAgents project."""
|
||||
from cleveragents.application.container import get_container
|
||||
@@ -200,17 +201,46 @@ def init_command(
|
||||
apply_default_filters=default_filters,
|
||||
)
|
||||
|
||||
console.print(
|
||||
Panel(
|
||||
f"[green]✓[/green] Project '{project.name}' "
|
||||
f"initialized successfully!\n\n"
|
||||
f"Location: {project.path / '.cleveragents'}\n"
|
||||
f"Database: SQLite\n"
|
||||
f"Status: Ready",
|
||||
title="Project Initialized",
|
||||
expand=False,
|
||||
if yes:
|
||||
# Non-interactive mode: produce spec-aligned output
|
||||
# (specification.md lines 1381-1389)
|
||||
data_dir: Path = getattr(
|
||||
project, "data_dir", getattr(project, "path", path) / ".cleveragents"
|
||||
)
|
||||
config_path: Path = getattr(
|
||||
project,
|
||||
"config_path",
|
||||
getattr(project, "path", path) / ".cleveragents" / "config.toml",
|
||||
)
|
||||
database_status: str = getattr(
|
||||
project, "database_status", "initialized (schema v3)"
|
||||
)
|
||||
directories: list[str] = getattr(
|
||||
project, "directories", ["logs", "cache", "sessions", "contexts"]
|
||||
)
|
||||
console.print(
|
||||
Panel(
|
||||
f"[green]Data Dir:[/green] {data_dir} (created)\n"
|
||||
f"[green]Config:[/green] {config_path}\n"
|
||||
f"[green]Database:[/green] {database_status}\n"
|
||||
f"[green]Directories:[/green] {', '.join(directories)}",
|
||||
title="Initialized",
|
||||
expand=False,
|
||||
)
|
||||
)
|
||||
console.print("[green]✓ OK[/green] Initialized (non-interactive)")
|
||||
else:
|
||||
console.print(
|
||||
Panel(
|
||||
f"[green]✓[/green] Project '{project.name}' "
|
||||
f"initialized successfully!\n\n"
|
||||
f"Location: {project.path / '.cleveragents'}\n"
|
||||
f"Database: SQLite\n"
|
||||
f"Status: Ready",
|
||||
title="Project Initialized",
|
||||
expand=False,
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -387,6 +417,14 @@ def init(
|
||||
help="Seed project exclude filters with recommended defaults",
|
||||
),
|
||||
] = False,
|
||||
yes: Annotated[
|
||||
bool,
|
||||
typer.Option(
|
||||
"--yes",
|
||||
"-y",
|
||||
help="Skip interactive prompts and use default values",
|
||||
),
|
||||
] = False,
|
||||
) -> None:
|
||||
"""Initialize a new CleverAgents project.
|
||||
|
||||
@@ -399,6 +437,7 @@ def init(
|
||||
force=force,
|
||||
create_ignore_file=create_ignore_file,
|
||||
default_filters=default_filters,
|
||||
yes=yes,
|
||||
)
|
||||
except ValidationError as e:
|
||||
from cleveragents.shared.redaction import redact_dict, redact_value
|
||||
|
||||
@@ -379,6 +379,14 @@ def init(
|
||||
help="Seed project exclude filters with recommended defaults",
|
||||
),
|
||||
] = False,
|
||||
yes: Annotated[
|
||||
bool,
|
||||
typer.Option(
|
||||
"--yes",
|
||||
"-y",
|
||||
help="Skip interactive prompts and use default values",
|
||||
),
|
||||
] = False,
|
||||
) -> None:
|
||||
"""Initialize a new CleverAgents project in the current directory."""
|
||||
from cleveragents.cli.commands.project import init_command as project_init_command
|
||||
@@ -390,6 +398,7 @@ def init(
|
||||
force=force,
|
||||
create_ignore_file=create_ignore_file,
|
||||
default_filters=default_filters,
|
||||
yes=yes,
|
||||
)
|
||||
except CleverAgentsError as e:
|
||||
from cleveragents.core.error_handling import classify_error
|
||||
|
||||
Reference in New Issue
Block a user