1use std::path::PathBuf;
2use std::str::FromStr;
3
4use clap::{ArgAction, Parser, ValueEnum};
5use tea_protocol::{ProfileId, ReasoningEffort, SessionId};
6use tea_provider_openai::ApiKey;
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
10pub enum TrustArg {
11 Default,
13 Once,
15 Persist,
17 Reject,
19 Ignore,
21}
22
23#[derive(Debug, Clone, Copy, PartialEq, Eq)]
25pub enum SessionSelection {
26 New,
28 Continue,
30 Existing(SessionId),
32 NoSession,
34}
35
36#[derive(Debug, Clone, Parser)]
38#[command(name = "tea", version = crate::version())]
39#[allow(clippy::struct_excessive_bools)] pub struct CliArgs {
41 #[arg(long, conflicts_with_all = ["json", "rpc"])]
43 pub print: bool,
44 #[arg(long, conflicts_with_all = ["print", "rpc"])]
46 pub json: bool,
47 #[arg(long, conflicts_with_all = ["print", "json"])]
49 pub rpc: bool,
50 #[arg(long, value_name = "DIR")]
52 pub cwd: Option<PathBuf>,
53 #[arg(long)]
55 pub provider: Option<String>,
56 #[arg(long)]
58 pub model: Option<String>,
59 #[arg(long)]
61 pub reasoning_effort: Option<ReasoningEffort>,
62 #[arg(long, value_name = "SECRET")]
64 pub api_key: Option<ApiKey>,
65 #[arg(long, default_value = "coding-agent")]
67 pub profile: String,
68 #[arg(long, value_delimiter = ',', action = ArgAction::Append)]
70 pub tools: Vec<String>,
71 #[arg(long = "context-file", value_name = "PATH")]
73 pub context_files: Vec<String>,
74 #[arg(long, conflicts_with_all = ["new_session", "continue_session", "no_session"])]
76 pub session: Option<String>,
77 #[arg(long = "new", conflicts_with_all = ["session", "continue_session", "no_session"])]
79 pub new_session: bool,
80 #[arg(long = "continue", conflicts_with_all = ["session", "new_session", "no_session"])]
82 pub continue_session: bool,
83 #[arg(long, conflicts_with_all = ["session", "new_session", "continue_session"])]
85 pub no_session: bool,
86 #[arg(long, value_name = "DIR")]
88 pub config_dir: Option<PathBuf>,
89 #[arg(long, value_name = "DIR")]
91 pub state_dir: Option<PathBuf>,
92 #[arg(long, value_name = "DIR")]
94 pub data_dir: Option<PathBuf>,
95 #[arg(long, value_name = "PATH")]
97 pub session_db: Option<PathBuf>,
98 #[arg(long, value_enum, default_value = "default")]
100 pub trust: TrustArg,
101 #[arg(short, long, action = ArgAction::Count)]
103 pub verbose: u8,
104 #[arg(value_name = "PROMPT")]
106 pub prompt: Vec<String>,
107}
108
109impl CliArgs {
110 pub fn session_selection(&self) -> Result<SessionSelection, crate::CliFailure> {
116 if let Some(session) = &self.session {
117 return SessionId::from_str(session)
118 .map(SessionSelection::Existing)
119 .map_err(|_| crate::CliFailure::usage("session identifier is invalid"));
120 }
121 if self.continue_session {
122 Ok(SessionSelection::Continue)
123 } else if self.no_session {
124 Ok(SessionSelection::NoSession)
125 } else {
126 Ok(SessionSelection::New)
127 }
128 }
129
130 pub fn profile_id(&self) -> Result<ProfileId, crate::CliFailure> {
136 ProfileId::from_str(&self.profile)
137 .map_err(|_| crate::CliFailure::usage("profile selector is invalid"))
138 }
139}