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    /// List all sessions.
59    #[arg(long)]
60    pub list_sessions: bool,
61
62    /// Resume a session by ID.
63    #[arg(long)]
64    pub resume: Option<String>,
65
66    /// Delete a session by ID.
67    #[arg(long)]
68    pub delete_session: Option<String>,
69
70    /// Generate shell completions to stdout.
71    #[arg(long, value_name = "SHELL")]
72    pub generate_completion: Option<ShellName>,
73
74    /// Enable debug tracing.
75    #[arg(short = 'v', long)]
76    pub verbose: bool,
77
78    /// Tool allowlist (comma-separated, e.g. "read,glob").
79    #[arg(long, value_delimiter = ',')]
80    pub tools: Option<Vec<String>>,
81
82    /// Disable all tools.
83    #[arg(long)]
84    pub no_tools: bool,
85
86    /// Disable built-in tools (reserved for Phase 4 extension tools).
87    #[arg(long)]
88    pub no_builtin_tools: bool,
89
90    /// Attach image file(s) to the prompt.
91    #[arg(long)]
92    pub image: Vec<PathBuf>,
93
94    /// List available models and exit.
95    #[arg(long)]
96    pub list_models: bool,
97
98    /// Initial prompt (positional).
99    #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
100    pub prompt: Vec<String>,
101}