mirror of
https://github.com/openai/codex.git
synced 2026-05-01 03:42:05 +03:00
38 lines
1.1 KiB
Rust
38 lines
1.1 KiB
Rust
use serde::Deserialize;
|
|
use serde::Serialize;
|
|
|
|
use crate::error::Error;
|
|
use crate::error::Result;
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)]
|
|
#[serde(rename_all = "camelCase")]
|
|
pub enum Decision {
|
|
/// Command may run without further approval.
|
|
Allow,
|
|
/// Request explicit user approval; rejected outright when running with `approval_policy="never"`.
|
|
Prompt,
|
|
/// Command is blocked without further consideration.
|
|
Forbidden,
|
|
}
|
|
|
|
impl Decision {
|
|
pub fn parse(raw: &str) -> Result<Self> {
|
|
match raw {
|
|
"allow" => Ok(Self::Allow),
|
|
"prompt" => Ok(Self::Prompt),
|
|
"forbidden" => Ok(Self::Forbidden),
|
|
other => Err(Error::InvalidDecision(other.to_string())),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl std::fmt::Display for Decision {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
match self {
|
|
Self::Allow => f.write_str("allow"),
|
|
Self::Prompt => f.write_str("prompt"),
|
|
Self::Forbidden => f.write_str("forbidden"),
|
|
}
|
|
}
|
|
}
|