59 lines
1.3 KiB
Python
59 lines
1.3 KiB
Python
"""Configuration management commands."""
|
|
|
|
import json
|
|
import os
|
|
|
|
import click
|
|
|
|
from mycli.config import config
|
|
|
|
|
|
@click.group(name="config")
|
|
def config_cmd():
|
|
"""Manage mycli configuration."""
|
|
pass
|
|
|
|
|
|
@config_cmd.command("show")
|
|
def show():
|
|
"""Show current configuration."""
|
|
config.show()
|
|
|
|
|
|
@config_cmd.command("get")
|
|
@click.argument("key")
|
|
def get_value(key):
|
|
"""Get a configuration value by key (dot notation)."""
|
|
value = config.get(key)
|
|
if value is not None:
|
|
if isinstance(value, dict):
|
|
print(json.dumps(value, indent=2, ensure_ascii=False))
|
|
else:
|
|
print(value)
|
|
else:
|
|
click.echo(f"Key not found: {key}", err=True)
|
|
raise click.Exit(1)
|
|
|
|
|
|
@config_cmd.command("paths")
|
|
def list_paths():
|
|
"""List all configured paths."""
|
|
paths = config.get_all_paths()
|
|
max_len = max(len(name) for name in paths.keys())
|
|
from pathlib import Path
|
|
for name, path in sorted(paths.items()):
|
|
exists = "✓" if path.exists() else "✗"
|
|
click.echo(f"{name:{max_len}} [{exists}] {path}")
|
|
|
|
|
|
@config_cmd.command("edit")
|
|
def edit():
|
|
"""Open configuration file in editor."""
|
|
config.edit()
|
|
|
|
|
|
@config_cmd.command("where")
|
|
def where():
|
|
"""Show configuration file location."""
|
|
click.echo(config._config_path)
|