品牌重塑: - Claude Code → Claw Code - .claude → .claw 配置目录 - CLAUDE_* → CLAW_* 环境变量 新增功能: - 多 Provider 架构 (ClawApi/Xai/OpenAI) - 插件系统 (生命周期/钩子/工具扩展) - LSP 集成 (诊断/代码智能) - Hook 系统 (PreToolUse/PostToolUse) - 独立 CLI (claw-cli) - HTTP Server (Axum/SSE) - Slash Commands 扩展 (branch/worktree/commit/pr/plugin等) 优化改进: - Compaction 支持增量压缩 - 全局工具注册表 - 配置文件统一为 .claw.json
105 lines
2.7 KiB
Rust
105 lines
2.7 KiB
Rust
use std::path::PathBuf;
|
|
|
|
use clap::{Parser, Subcommand, ValueEnum};
|
|
|
|
#[derive(Debug, Clone, Parser, PartialEq, Eq)]
|
|
#[command(name = "claw-cli", version, about = "Claw Code CLI")]
|
|
pub struct Cli {
|
|
#[arg(long, default_value = "claude-opus-4-6")]
|
|
pub model: String,
|
|
|
|
#[arg(long, value_enum, default_value_t = PermissionMode::DangerFullAccess)]
|
|
pub permission_mode: PermissionMode,
|
|
|
|
#[arg(long)]
|
|
pub config: Option<PathBuf>,
|
|
|
|
#[arg(long, value_enum, default_value_t = OutputFormat::Text)]
|
|
pub output_format: OutputFormat,
|
|
|
|
#[command(subcommand)]
|
|
pub command: Option<Command>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Subcommand, PartialEq, Eq)]
|
|
pub enum Command {
|
|
/// Read upstream TS sources and print extracted counts
|
|
DumpManifests,
|
|
/// Print the current bootstrap phase skeleton
|
|
BootstrapPlan,
|
|
/// Start the OAuth login flow
|
|
Login,
|
|
/// Clear saved OAuth credentials
|
|
Logout,
|
|
/// Run a non-interactive prompt and exit
|
|
Prompt { prompt: Vec<String> },
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, ValueEnum, PartialEq, Eq)]
|
|
pub enum PermissionMode {
|
|
ReadOnly,
|
|
WorkspaceWrite,
|
|
DangerFullAccess,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, ValueEnum, PartialEq, Eq)]
|
|
pub enum OutputFormat {
|
|
Text,
|
|
Json,
|
|
Ndjson,
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use clap::Parser;
|
|
|
|
use super::{Cli, Command, OutputFormat, PermissionMode};
|
|
|
|
#[test]
|
|
fn parses_requested_flags() {
|
|
let cli = Cli::parse_from([
|
|
"claw-cli",
|
|
"--model",
|
|
"claude-haiku-4-5-20251213",
|
|
"--permission-mode",
|
|
"read-only",
|
|
"--config",
|
|
"/tmp/config.toml",
|
|
"--output-format",
|
|
"ndjson",
|
|
"prompt",
|
|
"hello",
|
|
"world",
|
|
]);
|
|
|
|
assert_eq!(cli.model, "claude-haiku-4-5-20251213");
|
|
assert_eq!(cli.permission_mode, PermissionMode::ReadOnly);
|
|
assert_eq!(
|
|
cli.config.as_deref(),
|
|
Some(std::path::Path::new("/tmp/config.toml"))
|
|
);
|
|
assert_eq!(cli.output_format, OutputFormat::Ndjson);
|
|
assert_eq!(
|
|
cli.command,
|
|
Some(Command::Prompt {
|
|
prompt: vec!["hello".into(), "world".into()]
|
|
})
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn parses_login_and_logout_commands() {
|
|
let login = Cli::parse_from(["claw-cli", "login"]);
|
|
assert_eq!(login.command, Some(Command::Login));
|
|
|
|
let logout = Cli::parse_from(["claw-cli", "logout"]);
|
|
assert_eq!(logout.command, Some(Command::Logout));
|
|
}
|
|
|
|
#[test]
|
|
fn defaults_to_danger_full_access_permission_mode() {
|
|
let cli = Cli::parse_from(["claw-cli"]);
|
|
assert_eq!(cli.permission_mode, PermissionMode::DangerFullAccess);
|
|
}
|
|
}
|