Crates: - api: Anthropic Messages API client with SSE streaming - tools: Claude-compatible tool implementations (Bash, Read, Write, Edit, Glob, Grep + extended suite) - runtime: conversation loop, session persistence, permissions, system prompt builder - rusty-claude-cli: terminal UI with markdown rendering, syntax highlighting, spinners - commands: subcommand definitions - compat-harness: upstream TS parity verification All crates pass cargo fmt/clippy/test.
90 lines
2.2 KiB
Rust
90 lines
2.2 KiB
Rust
use std::path::PathBuf;
|
|
|
|
use clap::{Parser, Subcommand, ValueEnum};
|
|
|
|
#[derive(Debug, Clone, Parser, PartialEq, Eq)]
|
|
#[command(
|
|
name = "rusty-claude-cli",
|
|
version,
|
|
about = "Rust Claude CLI prototype"
|
|
)]
|
|
pub struct Cli {
|
|
#[arg(long, default_value = "claude-3-7-sonnet")]
|
|
pub model: String,
|
|
|
|
#[arg(long, value_enum, default_value_t = PermissionMode::WorkspaceWrite)]
|
|
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,
|
|
/// 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([
|
|
"rusty-claude-cli",
|
|
"--model",
|
|
"claude-3-5-haiku",
|
|
"--permission-mode",
|
|
"read-only",
|
|
"--config",
|
|
"/tmp/config.toml",
|
|
"--output-format",
|
|
"ndjson",
|
|
"prompt",
|
|
"hello",
|
|
"world",
|
|
]);
|
|
|
|
assert_eq!(cli.model, "claude-3-5-haiku");
|
|
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()]
|
|
})
|
|
);
|
|
}
|
|
}
|