Check if an event matches this matcher
(&self, event: &HookEvent)
| 107 | |
| 108 | /// Check if an event matches this matcher |
| 109 | pub fn matches(&self, event: &HookEvent) -> bool { |
| 110 | // Check session ID |
| 111 | if let Some(ref session_id) = self.session_id { |
| 112 | if event.session_id() != session_id { |
| 113 | return false; |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | // Check tool name |
| 118 | if let Some(ref tool_pattern) = self.tool { |
| 119 | if let Some(tool_name) = event.tool_name() { |
| 120 | if tool_name != tool_pattern { |
| 121 | return false; |
| 122 | } |
| 123 | } else { |
| 124 | // Event doesn't have a tool, but we're filtering by tool |
| 125 | return false; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | // Check path pattern (in tool args) |
| 130 | if let Some(ref path_pattern) = self.path_pattern { |
| 131 | if !self.matches_path_pattern(event, path_pattern) { |
| 132 | return false; |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | // Check command pattern (in Bash args) |
| 137 | if let Some(ref command_pattern) = self.command_pattern { |
| 138 | if !self.matches_command_pattern(event, command_pattern) { |
| 139 | return false; |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | // Check skill name (supports glob patterns) |
| 144 | if let Some(ref skill_pattern) = self.skill { |
| 145 | if let Some(skill_name) = event.skill_name() { |
| 146 | if !self.glob_match(skill_pattern, skill_name) { |
| 147 | return false; |
| 148 | } |
| 149 | } else { |
| 150 | // Event doesn't have a skill, but we're filtering by skill |
| 151 | return false; |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | true |
| 156 | } |
| 157 | |
| 158 | /// Check if event matches a path pattern (glob) |
| 159 | fn matches_path_pattern(&self, event: &HookEvent, pattern: &str) -> bool { |
nothing calls this directly
no test coverage detected