ai_agent/utils/shell/
shell_tool_utils.rs1pub const SHELL_TYPES: [&str; 2] = ["bash", "powershell"];
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum ShellType {
9 Bash,
10 PowerShell,
11}
12
13impl ShellType {
14 pub fn from_str(s: &str) -> Option<Self> {
16 match s.to_lowercase().as_str() {
17 "bash" => Some(Self::Bash),
18 "powershell" | "pwsh" => Some(Self::PowerShell),
19 _ => None,
20 }
21 }
22
23 pub fn as_str(&self) -> &str {
25 match self {
26 Self::Bash => "bash",
27 Self::PowerShell => "powershell",
28 }
29 }
30}
31
32impl Default for ShellType {
33 fn default() -> Self {
34 Self::Bash
35 }
36}
37
38pub const DEFAULT_HOOK_SHELL: ShellType = ShellType::Bash;
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44
45 #[test]
46 fn test_shell_type_from_str() {
47 assert_eq!(ShellType::from_str("bash"), Some(ShellType::Bash));
48 assert_eq!(ShellType::from_str("BASH"), Some(ShellType::Bash));
49 assert_eq!(
50 ShellType::from_str("powershell"),
51 Some(ShellType::PowerShell)
52 );
53 assert_eq!(ShellType::from_str("pwsh"), Some(ShellType::PowerShell));
54 assert_eq!(ShellType::from_str("unknown"), None);
55 }
56
57 #[test]
58 fn test_shell_type_as_str() {
59 assert_eq!(ShellType::Bash.as_str(), "bash");
60 assert_eq!(ShellType::PowerShell.as_str(), "powershell");
61 }
62}