Skip to content

config_cmd

config_cmd

jarvis config — configuration inspection commands.

Functions

config

config() -> None

Inspect configuration — show loaded settings, hardware, and config files.

Source code in src/openjarvis/cli/config_cmd.py
@click.group()
def config() -> None:
    """Inspect configuration — show loaded settings, hardware, and config files."""

show_group

show_group(ctx: Context, path: str | None, as_json: bool) -> None

Show configuration details.

Source code in src/openjarvis/cli/config_cmd.py
@click.group(invoke_without_command=True)
@click.option("--path", "-p", default=None, help="Explicit config file path")
@click.option("--json", "as_json", is_flag=True, default=False, help="Output as JSON")
@click.pass_context
def show_group(ctx: click.Context, path: str | None, as_json: bool) -> None:
    """Show configuration details."""
    # Default to 'loaded' if no subcommand is invoked
    if ctx.invoked_subcommand is None:
        console = Console(stderr=True)
        try:
            config_path = _get_config_path(path)
            _show_loaded_config(console, config_path, as_json)
        except Exception as exc:
            console.print(f"[red]Error: {exc}[/red]")

loaded

loaded(path: str | None, as_json: bool) -> None

Show the loaded effective configuration from config.toml.

Source code in src/openjarvis/cli/config_cmd.py
@show_group.command()
@click.option("--path", "-p", default=None, help="Explicit config file path")
@click.option("--json", "as_json", is_flag=True, default=False, help="Output as JSON")
def loaded(path: str | None, as_json: bool) -> None:
    """Show the loaded effective configuration from config.toml."""
    console = Console(stderr=True)
    try:
        config_path = _get_config_path(path)
        _show_loaded_config(console, config_path, as_json)
    except Exception as exc:
        console.print(f"[red]Error: {exc}[/red]")

toml

toml(path: str | None) -> None

Show the raw TOML configuration file content with syntax highlighting.

Source code in src/openjarvis/cli/config_cmd.py
@show_group.command()
@click.option("--path", "-p", default=None, help="Explicit config file path")
def toml(path: str | None) -> None:
    """Show the raw TOML configuration file content with syntax highlighting."""
    console = Console(stderr=True)
    try:
        config_path = _get_config_path(path)
        _show_toml_config(console, config_path)
    except Exception as exc:
        console.print(f"[red]Error: {exc}[/red]")

as_json

as_json(path: str | None) -> None

Show the parsed TOML configuration as JSON.

Source code in src/openjarvis/cli/config_cmd.py
@show_group.command("json")
@click.option("--path", "-p", default=None, help="Explicit config file path")
def as_json(path: str | None) -> None:
    """Show the parsed TOML configuration as JSON."""
    console = Console(stderr=True)
    try:
        config_path = _get_config_path(path)
        _show_json_config(console, config_path)
    except Exception as exc:
        console.print(f"[red]Error: {exc}[/red]")

hardware

hardware() -> None

Show detected hardware information with recommended engine and model.

Source code in src/openjarvis/cli/config_cmd.py
@show_group.command()
def hardware() -> None:
    """Show detected hardware information with recommended engine and model."""
    console = Console(stderr=True)
    try:
        _show_hardware(console)
    except Exception as exc:
        console.print(f"[red]Error: {exc}[/red]")

set_config

set_config(key: str, value: str) -> None

Set a configuration value (e.g. jarvis config set engine.ollama.host URL).

Source code in src/openjarvis/cli/config_cmd.py
@click.command("set")
@click.argument("key")
@click.argument("value")
def set_config(key: str, value: str) -> None:
    """Set a configuration value (e.g. jarvis config set engine.ollama.host URL)."""
    import tomlkit

    from openjarvis.core.config import DEFAULT_CONFIG_DIR, validate_config_key

    console = Console(stderr=True)

    # Validate key
    try:
        target_type = validate_config_key(key)
    except ValueError as exc:
        console.print(f"[red]Error:[/red] {exc}")
        raise SystemExit(1)

    # Coerce value
    try:
        typed_value = _coerce_value(value, target_type)
    except (ValueError, TypeError) as exc:
        console.print(
            f"[red]Error:[/red] Cannot convert {value!r} to "
            f"{target_type.__name__}: {exc}"
        )
        raise SystemExit(1)

    # Load or create TOML document
    config_path = Path(
        os.environ.get("OPENJARVIS_CONFIG", DEFAULT_CONFIG_DIR / "config.toml")
    )
    if config_path.exists():
        doc = tomlkit.parse(config_path.read_text())
    else:
        doc = tomlkit.document()
        config_path.parent.mkdir(parents=True, exist_ok=True)

    # Set nested key
    parts = key.split(".")
    current = doc
    for part in parts[:-1]:
        if part not in current:
            current.add(part, tomlkit.table())
        current = current[part]
    current[parts[-1]] = typed_value

    # Write back
    config_path.write_text(tomlkit.dumps(doc))

    console.print(f"[green]Set[/green] {key} = {value!r}")

    # Probe engine host if applicable
    if re.match(r"^engine\.\w+\.host$", key):
        _probe_engine_host(value, console)