vkit 0.1.2

Fast Rust dev CLI: manage Node ports, run scripts, install & sync VS Code / Cursor extensions.
mod dashboard;
mod ports;
mod preview;
mod run;
mod sync;
mod theme;
mod update;
mod vsix;
mod widgets;

use clap::{Parser, Subcommand};

#[derive(Parser)]
#[command(name = "vkit", version, about = "Fast Rust CLI companion for vkit")]
struct Cli {
    #[command(subcommand)]
    command: Option<Command>,
}

#[derive(Subcommand)]
enum Command {
    /// 管理 Node 端口:列出监听端口并一键关闭(仅 macOS)
    Port,
    /// 运行 scripts:扫描当前目录及子包的 package.json,多选批量运行
    Run,
    /// 安装插件:从 Marketplace 下载 VSIX 并装到 Cursor / VS Code
    Vsix,
    /// 同步插件:把 VS Code 已装扩展批量同步到 Cursor
    Sync,
    /// 主题预览:一屏查看所有主题色与组件样式
    Preview,
    /// 更新自身:从 GitHub Releases 下载最新版本并原地替换
    Update,
}

fn main() {
    let cli = Cli::parse();

    // update 是纯命令行输出,无需 TUI / 主题探测,单独提前处理。
    if let Some(Command::Update) = cli.command {
        if let Err(err) = update::run() {
            eprintln!("错误:{err:#}");
            std::process::exit(1);
        }
        return;
    }

    // 进入 TUI 前探测终端背景,自动选深/浅色主题;探测失败默认深色。
    let is_light = matches!(
        termbg::theme(std::time::Duration::from_millis(100)),
        Ok(termbg::Theme::Light)
    );
    theme::init(is_light);

    let result = match cli.command {
        Some(Command::Port) => ports::run(),
        Some(Command::Run) => run::run(),
        Some(Command::Vsix) => vsix::run(),
        Some(Command::Sync) => sync::run(),
        Some(Command::Preview) => preview::run(),
        Some(Command::Update) => unreachable!("update 已在前面提前处理"),
        None => dashboard::run(),
    };

    if let Err(err) = result {
        eprintln!("错误:{err:#}");
        std::process::exit(1);
    }
}