Skip to main content

codex/cli/
help.rs

1use crate::CliOverridesPatch;
2
3/// Selector for `codex help`-style command families.
4#[derive(Clone, Copy, Debug, Eq, PartialEq)]
5pub enum HelpScope {
6    Root,
7    Exec,
8    Features,
9    Login,
10    AppServer,
11    Sandbox,
12    Cloud,
13    Mcp,
14}
15
16impl HelpScope {
17    pub(crate) fn argv_prefix(&self) -> &'static [&'static str] {
18        match self {
19            HelpScope::Root => &["help"],
20            HelpScope::Exec => &["exec", "help"],
21            HelpScope::Features => &["features", "help"],
22            HelpScope::Login => &["login", "help"],
23            HelpScope::AppServer => &["app-server", "help"],
24            HelpScope::Sandbox => &["sandbox", "help"],
25            HelpScope::Cloud => &["cloud", "help"],
26            HelpScope::Mcp => &["mcp", "help"],
27        }
28    }
29}
30
31/// Request for `codex <scope> help [COMMAND]...`.
32#[derive(Clone, Debug, Eq, PartialEq)]
33pub struct HelpCommandRequest {
34    pub scope: HelpScope,
35    /// Optional command path components appended after `help` (variadic upstream).
36    pub command: Vec<String>,
37    /// Per-call CLI overrides layered on top of the builder.
38    pub overrides: CliOverridesPatch,
39}
40
41impl HelpCommandRequest {
42    pub fn new(scope: HelpScope) -> Self {
43        Self {
44            scope,
45            command: Vec::new(),
46            overrides: CliOverridesPatch::default(),
47        }
48    }
49
50    /// Appends one or more command tokens to the help invocation.
51    pub fn command<I, S>(mut self, tokens: I) -> Self
52    where
53        I: IntoIterator<Item = S>,
54        S: Into<String>,
55    {
56        self.command.extend(tokens.into_iter().map(Into::into));
57        self
58    }
59
60    /// Replaces the default CLI overrides for this request.
61    pub fn with_overrides(mut self, overrides: CliOverridesPatch) -> Self {
62        self.overrides = overrides;
63        self
64    }
65}