feat(cli): add --config option to channels login and status commands

Allows users to specify custom config file paths when managing channels.

Usage:
  nanobot channels login weixin --config .nanobot-feishu/config.json
    nanobot channels status -c .nanobot-qq/config.json

    - Added optional --config/-c parameter to both commands
    - Defaults to ~/.nanobot/config.json when not specified
    - Maintains backward compatibility
This commit is contained in:
masterlyj 2026-04-02 13:49:08 +08:00 committed by Xubin Ren
parent 7a6416bcb2
commit 7332d133a7

View File

@ -1023,12 +1023,14 @@ app.add_typer(channels_app, name="channels")
@channels_app.command("status")
def channels_status():
def channels_status(
config_path: str | None = typer.Option(None, "--config", "-c", help="Path to config file"),
):
"""Show channel status."""
from nanobot.channels.registry import discover_all
from nanobot.config.loader import load_config
config = load_config()
config = load_config(Path(config_path) if config_path else None)
table = Table(title="Channel Status")
table.add_column("Channel", style="cyan")
@ -1115,12 +1117,13 @@ def _get_bridge_dir() -> Path:
def channels_login(
channel_name: str = typer.Argument(..., help="Channel name (e.g. weixin, whatsapp)"),
force: bool = typer.Option(False, "--force", "-f", help="Force re-authentication even if already logged in"),
config_path: str | None = typer.Option(None, "--config", "-c", help="Path to config file"),
):
"""Authenticate with a channel via QR code or other interactive login."""
from nanobot.channels.registry import discover_all
from nanobot.config.loader import load_config
config = load_config()
config = load_config(Path(config_path) if config_path else None)
channel_cfg = getattr(config.channels, channel_name, None) or {}
# Validate channel exists