use std::fmt;
use std::str::FromStr;
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default, Hash)]
pub enum PermissionMode {
#[default]
AutoEdit,
AutoEditAddressComments,
ReadOnly,
}
impl PermissionMode {
pub const ALL: [PermissionMode; 3] = [
PermissionMode::AutoEdit,
PermissionMode::AutoEditAddressComments,
PermissionMode::ReadOnly,
];
pub fn description(self) -> &'static str {
match self {
Self::AutoEdit => "Allow the agent to edit files automatically.",
Self::AutoEditAddressComments => {
"Auto Edit, then address focused-review suggestions up to 3 times."
}
Self::ReadOnly => "Inspect the repository without changing files.",
}
}
pub fn label(self) -> &'static str {
match self {
Self::AutoEdit => "auto_edit",
Self::AutoEditAddressComments => "auto_edit_address_comments",
Self::ReadOnly => "read_only",
}
}
pub fn display_label(self) -> &'static str {
match self {
Self::AutoEdit => "Auto Edit",
Self::AutoEditAddressComments => "Auto Edit + Auto Address Comments",
Self::ReadOnly => "Read Only",
}
}
pub fn is_read_only(self) -> bool {
self == Self::ReadOnly
}
}
impl fmt::Display for PermissionMode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.label())
}
}
impl FromStr for PermissionMode {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"auto_edit" => Ok(PermissionMode::AutoEdit),
"auto_edit_address_comments" => Ok(PermissionMode::AutoEditAddressComments),
"read_only" => Ok(PermissionMode::ReadOnly),
_ => Err(format!("Unknown permission mode: {s}")),
}
}
}
#[cfg(test)]
#[path = "permission_test.rs"]
mod tests;