MCPcopy Create free account
hub / github.com/AI45Lab/Code / matches_command_pattern

Method matches_command_pattern

core/src/hooks/matcher.rs:178–203  ·  view source on GitHub ↗

Check if event matches a command pattern (regex)

(&self, event: &HookEvent, pattern: &str)

Source from the content-addressed store, hash-verified

176
177 /// Check if event matches a command pattern (regex)
178 fn matches_command_pattern(&self, event: &HookEvent, pattern: &str) -> bool {
179 // Only applies to Bash tool
180 if event.tool_name() != Some("Bash") && event.tool_name() != Some("bash") {
181 return false;
182 }
183
184 let args = match event.tool_args() {
185 Some(args) => args,
186 None => return false,
187 };
188
189 let command = args.get("command").and_then(|v| v.as_str());
190
191 match command {
192 Some(cmd) => {
193 // Use regex matching
194 if let Ok(re) = regex::Regex::new(pattern) {
195 re.is_match(cmd)
196 } else {
197 // Fallback to contains if regex is invalid
198 cmd.contains(pattern)
199 }
200 }
201 None => false,
202 }
203 }
204
205 /// Simple glob matching (supports * and **)
206 ///

Callers 1

matchesMethod · 0.80

Calls 5

tool_nameMethod · 0.80
tool_argsMethod · 0.80
containsMethod · 0.80
getMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected