refactor: rename paths

This commit is contained in:
wancat committed 2024-03-07 00:50:42 +08:00
1 parent e5f5590a67
commit b5e20766a3
12 files changed
+52 -52

No files matched your search

+31
View File
@@ -0,0 +1,31 @@
/* eslint-disable max-classes-per-file */
import { Command, ICondition } from '../types.js'
import { PwdMatcher } from './PwdMatcher.js'
import { CommandMatcher } from './CommandMatcher.js'
import { ErrorMatcher } from './ErrorMatcher.js'
import { Matcher } from './Matcher.js'
import { OutputMatcher } from './OutputMatcher.js'
import { OrMatcher } from './OrMatcher.js'
import { NotMatcher } from './NotMatcher.js'
export class Condition {
private matchers: Matcher[] = []
constructor({ command, output, error, pwd, or, not }: ICondition) {
if (command) this.matchers.push(new CommandMatcher(command))
if (output) this.matchers.push(new OutputMatcher(output))
if (pwd) this.matchers.push(new PwdMatcher(pwd))
if (or) {
const conditions = or.map((condition) => new Condition(condition))
this.matchers.push(new OrMatcher(conditions))
}
if (not) this.matchers.push(new NotMatcher(new Condition(not)))
this.matchers.push(new ErrorMatcher(error)) // always check unexpected error
}
match(command: Command): boolean {
return this.matchers.every((matcher) => {
return matcher.match(command)
})
}
}