Skip to main content

ai_agent/tools/powershell/
common_parameters.rs

1// Source: /data/home/swei/claudecode/openclaudecode/src/tools/PowerShellTool/commonParameters.ts
2//! PowerShell Common Parameters
3//!
4//! PowerShell Common Parameters (available on all cmdlets via [CmdletBinding()]).
5//! Source: about_CommonParameters (PowerShell docs) + Get-Command output.
6//!
7//! Shared between pathValidation.ts (merges into per-cmdlet known-param sets)
8//! and readOnlyValidation.ts (merges into safeFlags check). Split out to break
9//! what would otherwise be an import cycle between those two files.
10//!
11//! Stored lowercase with leading dash — callers `.toLowerCase()` their input.
12
13use std::collections::HashSet;
14
15/// Common switch parameters
16pub const COMMON_SWITCHES: &[&str] = &["-verbose", "-debug"];
17
18/// Common value parameters
19pub const COMMON_VALUE_PARAMS: &[&str] = &[
20    "-erroraction",
21    "-warningaction",
22    "-informationaction",
23    "-progressaction",
24    "-errorvariable",
25    "-warningvariable",
26    "-informationvariable",
27    "-outvariable",
28    "-outbuffer",
29    "-pipelinevariable",
30];
31
32/// All common parameters
33pub fn common_parameters() -> HashSet<&'static str> {
34    let mut set = HashSet::new();
35    for s in COMMON_SWITCHES {
36        set.insert(*s);
37    }
38    for s in COMMON_VALUE_PARAMS {
39        set.insert(*s);
40    }
41    set
42}
43
44#[cfg(test)]
45mod tests {
46    use super::*;
47
48    #[test]
49    fn test_common_switches() {
50        assert!(COMMON_SWITCHES.contains(&"-verbose"));
51        assert!(COMMON_SWITCHES.contains(&"-debug"));
52    }
53
54    #[test]
55    fn test_common_value_params() {
56        assert!(COMMON_VALUE_PARAMS.contains(&"-erroraction"));
57        assert!(COMMON_VALUE_PARAMS.contains(&"-outvariable"));
58    }
59
60    #[test]
61    fn test_common_parameters() {
62        let params = common_parameters();
63        assert!(params.contains("-verbose"));
64        assert!(params.contains("-debug"));
65        assert!(params.contains("-erroraction"));
66        assert!(params.contains("-warningaction"));
67        assert!(params.contains("-outvariable"));
68    }
69
70    #[test]
71    fn test_common_parameters_count() {
72        let params = common_parameters();
73        // 2 switches + 10 value params = 12
74        assert_eq!(params.len(), 12);
75    }
76
77    #[test]
78    fn test_common_parameters_case_sensitive() {
79        let params = common_parameters();
80        assert!(params.contains("-verbose"));
81        assert!(!params.contains("-VERBOSE"));
82    }
83}