| 1 | use serde::Deserialize; |
| 2 | use serde::Serialize; |
| 3 | |
| 4 | use super::error::Error; |
| 5 | use super::error::Result; |
| 6 | |
| 7 | #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)] |
| 8 | #[serde(rename_all = "camelCase")] |
| 9 | pub enum Decision { |
| 10 | /// Command may run without further approval. |
| 11 | Allow, |
| 12 | /// Request explicit user approval; rejected outright when running with `approval_policy="never"`. |
| 13 | Prompt, |
| 14 | /// Command is blocked without further consideration. |
| 15 | Forbidden, |
| 16 | } |
| 17 | |
| 18 | impl Decision { |
| 19 | pub fn parse(raw: &str) -> Result<Self> { |
| 20 | match raw { |
| 21 | "allow" => Ok(Self::Allow), |
| 22 | "prompt" => Ok(Self::Prompt), |
| 23 | "forbidden" => Ok(Self::Forbidden), |
| 24 | other => Err(Error::InvalidDecision(other.to_string())), |
| 25 | } |
| 26 | } |
| 27 | } |
| 28 |