mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
refactor: rename paths
This commit is contained in:
1 parent
e5f5590a67
commit
b5e20766a3
12 files changed
+52
-52
No files matched your search
@@ -1,6 +0,0 @@
|
||||
export interface Command {
|
||||
command: string
|
||||
output: string
|
||||
error: string
|
||||
pwd: string
|
||||
}
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
import { Command } from '../command.js'
|
||||
import { Matcher } from './matcher.js'
|
||||
import { Command } from '../types.js'
|
||||
import { Matcher } from './Matcher.js'
|
||||
|
||||
export class CommandMatcher implements Matcher {
|
||||
private matcher: RegExp
|
||||
@@ -7,7 +7,7 @@ export class CommandMatcher implements Matcher {
|
||||
this.matcher = new RegExp(command, flags)
|
||||
}
|
||||
|
||||
match(command: Partial<Command>): boolean {
|
||||
match(command: Command): boolean {
|
||||
return !!command.command && this.matcher.test(command.command)
|
||||
}
|
||||
}
|
||||
+9
-18
@@ -1,21 +1,12 @@
|
||||
/* eslint-disable max-classes-per-file */
|
||||
import { Command } from '../command.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 interface ICondition {
|
||||
command?: string
|
||||
output?: string
|
||||
error?: string
|
||||
pwd?: string
|
||||
or?: ICondition[]
|
||||
not?: ICondition
|
||||
}
|
||||
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[] = []
|
||||
@@ -32,7 +23,7 @@ export class Condition {
|
||||
this.matchers.push(new ErrorMatcher(error)) // always check unexpected error
|
||||
}
|
||||
|
||||
match(command: Partial<Command>): boolean {
|
||||
match(command: Command): boolean {
|
||||
return this.matchers.every((matcher) => {
|
||||
return matcher.match(command)
|
||||
})
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
import { Matcher } from './matcher.js'
|
||||
import { Command } from '../command.js'
|
||||
import { Matcher } from './Matcher.js'
|
||||
import { Command } from '../types.js'
|
||||
|
||||
export class ErrorMatcher implements Matcher {
|
||||
private matcher?: RegExp
|
||||
@@ -9,7 +9,7 @@ export class ErrorMatcher implements Matcher {
|
||||
}
|
||||
}
|
||||
|
||||
match(command: Partial<Command>): boolean {
|
||||
match(command: Command): boolean {
|
||||
if (!this.matcher) {
|
||||
return !command.error
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { Command } from '../types.js'
|
||||
|
||||
export interface Matcher {
|
||||
match(command: Command): boolean
|
||||
}
|
||||
+3
-3
@@ -1,10 +1,10 @@
|
||||
import { Command } from '../command.js'
|
||||
import { Matcher } from './matcher.js'
|
||||
import { Command } from '../types.js'
|
||||
import { Matcher } from './Matcher.js'
|
||||
|
||||
export class NotMatcher implements Matcher {
|
||||
constructor(private condition: Matcher) {}
|
||||
|
||||
match(command: Partial<Command>): boolean {
|
||||
match(command: Command): boolean {
|
||||
return !this.condition.match(command)
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Command } from '../command.js'
|
||||
import { Matcher } from './matcher.js'
|
||||
import { Command } from '../types.js'
|
||||
import { Matcher } from './Matcher.js'
|
||||
|
||||
export class OrMatcher implements Matcher {
|
||||
constructor(private conditions: Matcher[]) {}
|
||||
|
||||
match(command: Partial<Command>): boolean {
|
||||
match(command: Command): boolean {
|
||||
return this.conditions.some((condition) => condition.match(command))
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
import { Command } from '../command.js'
|
||||
import { Matcher } from './matcher.js'
|
||||
import { Command } from '../types.js'
|
||||
import { Matcher } from './Matcher.js'
|
||||
|
||||
export class OutputMatcher implements Matcher {
|
||||
private matcher: RegExp
|
||||
@@ -7,7 +7,7 @@ export class OutputMatcher implements Matcher {
|
||||
this.matcher = new RegExp(pattern, args)
|
||||
}
|
||||
|
||||
match(command: Partial<Command>): boolean {
|
||||
match(command: Command): boolean {
|
||||
return !!command.output && this.matcher.test(command.output.trim())
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -1,10 +1,10 @@
|
||||
import { Command } from '../command.js'
|
||||
import { Matcher } from './matcher.js'
|
||||
import { Command } from '../types.js'
|
||||
import { Matcher } from './Matcher.js'
|
||||
|
||||
export class PwdMatcher implements Matcher {
|
||||
constructor(private pwd: string) {}
|
||||
|
||||
match(command: Partial<Command>): boolean {
|
||||
match(command: Command): boolean {
|
||||
return command.pwd === this.pwd
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
import { Command } from '../command.js'
|
||||
|
||||
export interface Matcher {
|
||||
match(command: Partial<Command>): boolean
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
export interface Command {
|
||||
command?: string
|
||||
output?: string
|
||||
error?: string
|
||||
pwd?: string
|
||||
}
|
||||
|
||||
export interface ICondition {
|
||||
command?: string
|
||||
output?: string
|
||||
error?: string
|
||||
pwd?: string
|
||||
or?: ICondition[]
|
||||
not?: ICondition
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
import { test, expect } from '@jest/globals'
|
||||
import { Condition } from '../src/condition/condition'
|
||||
import { OutputMatcher } from '../src/condition/outputMatcher'
|
||||
import { PwdMatcher } from '../src/condition/pwdMatcher'
|
||||
import { CommandMatcher } from '../src/condition/commandMatcher'
|
||||
import { ErrorMatcher } from '../src/condition/errorMatcher.js'
|
||||
import { Condition } from '../src/condition/Condition'
|
||||
import { OutputMatcher } from '../src/condition/OutputMatcher'
|
||||
import { PwdMatcher } from '../src/condition/PwdMatcher'
|
||||
import { CommandMatcher } from '../src/condition/CommandMatcher'
|
||||
import { ErrorMatcher } from '../src/condition/ErrorMatcher.js'
|
||||
|
||||
test('command match', () => {
|
||||
const matcher = new CommandMatcher('^echo start$')
|
||||
|
||||
Reference in new issue
Block a user