refactor: remove unnecessary patter matcher

This commit is contained in:
wancat committed 2024-03-06 23:57:35 +08:00
1 parent 4f3752060d
commit 8280f7073d
2 files changed
+11 -33

No files matched your search

+11 -12
View File
@@ -2,28 +2,22 @@
import { Command } from './command'
import { Matcher } from './matcher'
export class PatternMatcher {
export class CommandMatcher implements Matcher {
private matcher: RegExp
constructor(pattern: string, args?: string) {
this.matcher = new RegExp(pattern, args)
}
test(input: string): boolean {
return this.matcher.test(input)
}
}
export class CommandMatcher extends PatternMatcher implements Matcher {
match(command: Partial<Command>): boolean {
return !!command.command && this.test(command.command)
return !!command.command && this.matcher.test(command.command)
}
}
export class ErrorMatcher implements Matcher {
private matcher?: PatternMatcher
private matcher?: RegExp
constructor(errorPattern?: string) {
if (errorPattern) {
this.matcher = new PatternMatcher(errorPattern)
this.matcher = new RegExp(errorPattern)
}
}
@@ -43,9 +37,14 @@ export class PwdMatcher implements Matcher {
}
}
export class OutputMatcher extends PatternMatcher implements Matcher {
export class OutputMatcher implements Matcher {
private matcher: RegExp
constructor(pattern: string, args?: string) {
this.matcher = new RegExp(pattern, args)
}
match(command: Partial<Command>): boolean {
return command.output ? this.test(command.output.trim()) : false
return !!command.output && this.matcher.test(command.output.trim())
}
}