-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.rs
More file actions
182 lines (149 loc) · 4.5 KB
/
cli.rs
File metadata and controls
182 lines (149 loc) · 4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
//! CLI argument parsing module.
//!
//! Extracts CLI arguments into a separate module for better organization.
use clap::{Parser, Subcommand};
/// CLI argument parser
#[derive(Parser, Debug)]
#[command(name = "do-wdr")]
#[command(about = "Web Documentation Resolver - Resolve URLs and queries into documentation", long_about = None)]
#[command(version = "0.3.1")]
pub struct Cli {
#[command(subcommand)]
pub command: Commands,
/// Enable verbose logging (-v, -vv, -vvv)
#[arg(short, long, action = clap::ArgAction::Count)]
pub verbose: u8,
}
/// CLI commands
#[derive(Subcommand, Debug)]
pub enum Commands {
/// Resolve a URL or query to markdown documentation
Resolve(Box<ResolveArgs>),
/// List available providers
Providers,
/// Show configuration
Config,
/// Show cache statistics
CacheStats,
}
#[derive(Parser, Debug, Clone)]
pub struct ResolveArgs {
/// URL or query to resolve
pub input: String,
/// Output file (stdout if not specified)
#[arg(short, long)]
pub output: Option<String>,
/// Provider to use (auto-detect if not specified)
#[arg(short, long)]
pub provider: Option<String>,
/// Skip specific providers (comma-separated)
#[arg(long)]
pub skip: Option<String>,
/// Custom provider order (comma-separated)
#[arg(long)]
pub providers_order: Option<String>,
/// Maximum characters in output
#[arg(long)]
pub max_chars: Option<usize>,
/// Minimum characters for valid content
#[arg(long)]
pub min_chars: Option<usize>,
/// Execution profile (free, balanced, fast, quality)
#[arg(long)]
pub profile: Option<String>,
/// Output as JSON
#[arg(long, default_value = "false")]
pub json: bool,
/// Output metrics as JSON
#[arg(long, default_value = "false")]
pub metrics_json: bool,
/// Save metrics to file
#[arg(long)]
pub metrics_file: Option<String>,
/// Skip semantic cache
#[arg(long, default_value = "false")]
pub skip_cache: bool,
/// Synthesize multiple results using AI
#[arg(long, default_value = "false")]
pub synthesize: bool,
/// Quality threshold for content scoring
#[arg(long)]
pub quality_threshold: Option<f32>,
/// Maximum provider attempts
#[arg(long)]
pub max_provider_attempts: Option<usize>,
/// Maximum paid provider attempts
#[arg(long)]
pub max_paid_attempts: Option<usize>,
/// Maximum total latency in milliseconds
#[arg(long)]
pub max_total_latency_ms: Option<u64>,
/// Disable routing memory
#[arg(long, default_value_t = false)]
pub disable_routing_memory: bool,
}
impl Cli {
/// Parse CLI arguments
pub fn parse_args() -> Self {
Cli::parse()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_cli_parse_resolve() {
let cli = Cli::parse_from(["do-wdr", "resolve", "https://example.com"]);
match cli.command {
Commands::Resolve(args) => {
assert_eq!(args.input, "https://example.com");
}
_ => panic!("Expected Resolve command"),
}
}
#[test]
fn test_cli_parse_resolve_with_options() {
let cli = Cli::parse_from([
"do-wdr",
"resolve",
"test query",
"--provider",
"exa",
"--skip",
"tavily",
"--json",
]);
match cli.command {
Commands::Resolve(args) => {
assert_eq!(args.input, "test query");
assert_eq!(args.provider, Some("exa".to_string()));
assert_eq!(args.skip, Some("tavily".to_string()));
assert!(args.json);
}
_ => panic!("Expected Resolve command"),
}
}
#[test]
fn test_cli_parse_providers() {
let cli = Cli::parse_from(["do-wdr", "providers"]);
match cli.command {
Commands::Providers => {}
_ => panic!("Expected Providers command"),
}
}
#[test]
fn test_cli_parse_config() {
let cli = Cli::parse_from(["do-wdr", "config"]);
match cli.command {
Commands::Config => {}
_ => panic!("Expected Config command"),
}
}
#[test]
fn test_cli_verbose_flag() {
let cli = Cli::parse_from(["do-wdr", "-v", "resolve", "test"]);
assert_eq!(cli.verbose, 1);
let cli = Cli::parse_from(["do-wdr", "-vv", "resolve", "test"]);
assert_eq!(cli.verbose, 2);
}
}