Skip to main content

opi_coding_agent/
cli.rs

1//! CLI argument parsing (S8.4).
2
3use std::path::PathBuf;
4
5use clap::{Parser, ValueEnum};
6
7/// Supported shells for completion generation.
8#[derive(Debug, Clone, Copy, ValueEnum)]
9pub enum ShellName {
10    Bash,
11    Zsh,
12    Fish,
13    #[clap(name = "powershell")]
14    PowerShell,
15    Elvish,
16}
17
18impl From<ShellName> for clap_complete::Shell {
19    fn from(s: ShellName) -> Self {
20        match s {
21            ShellName::Bash => clap_complete::Shell::Bash,
22            ShellName::Zsh => clap_complete::Shell::Zsh,
23            ShellName::Fish => clap_complete::Shell::Fish,
24            ShellName::PowerShell => clap_complete::Shell::PowerShell,
25            ShellName::Elvish => clap_complete::Shell::Elvish,
26        }
27    }
28}
29
30/// opi — AI coding agent.
31#[derive(Debug, Parser)]
32#[command(name = "opi", version, about = "AI coding agent")]
33pub struct Cli {
34    /// Model spec, e.g. anthropic:claude-sonnet-4.
35    #[arg(short = 'm', long)]
36    pub model: Option<String>,
37
38    /// Config file path.
39    #[arg(short = 'c', long)]
40    pub config: Option<PathBuf>,
41
42    /// System prompt file.
43    #[arg(short = 's', long)]
44    pub system: Option<PathBuf>,
45
46    /// Single prompt mode (non-interactive).
47    #[arg(long)]
48    pub non_interactive: bool,
49
50    /// Allow mutating tools (write, edit, bash) in non-interactive mode.
51    #[arg(long)]
52    pub allow_mutating: bool,
53
54    /// Output NDJSON events to stdout (non-interactive mode).
55    #[arg(long)]
56    pub json: bool,
57
58    /// RPC JSONL mode: bidirectional command/event protocol over stdin/stdout.
59    #[arg(long)]
60    pub rpc: bool,
61
62    /// List all sessions.
63    #[arg(long)]
64    pub list_sessions: bool,
65
66    /// Resume a session by ID.
67    #[arg(long)]
68    pub resume: Option<String>,
69
70    /// Delete a session by ID.
71    #[arg(long)]
72    pub delete_session: Option<String>,
73
74    /// Generate shell completions to stdout.
75    #[arg(long, value_name = "SHELL")]
76    pub generate_completion: Option<ShellName>,
77
78    /// Enable debug tracing.
79    #[arg(short = 'v', long)]
80    pub verbose: bool,
81
82    /// Tool allowlist (comma-separated, e.g. "read,glob").
83    #[arg(long, value_delimiter = ',')]
84    pub tools: Option<Vec<String>>,
85
86    /// Disable all tools.
87    #[arg(long)]
88    pub no_tools: bool,
89
90    /// Disable built-in tools (reserved for Phase 4 extension tools).
91    #[arg(long)]
92    pub no_builtin_tools: bool,
93
94    /// Attach image file(s) to the prompt.
95    #[arg(long)]
96    pub image: Vec<PathBuf>,
97
98    /// List available models and exit.
99    #[arg(long)]
100    pub list_models: bool,
101
102    /// Initial prompt (positional).
103    #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
104    pub prompt: Vec<String>,
105}