mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
feat: implement $not and $or condition
This commit is contained in:
1 parent
e52682686a
commit
b7ecfe3980
4 files changed
+42
-166
No files matched your search
@@ -53,10 +53,14 @@ export default class CommandHandler extends SessionHandler {
|
||||
this.session.graph = graph
|
||||
}
|
||||
|
||||
isMatch(stage) {
|
||||
isMatch(condition) {
|
||||
const keys = ['command', 'output', 'error', 'pwd']
|
||||
return keys.every((k) =>
|
||||
checkMatch(stage.condition[k], this.commandInput[k])
|
||||
console.log('condition', condition)
|
||||
return (
|
||||
keys.every((k) => checkMatch(condition[k], this.commandInput[k])) &&
|
||||
(condition.$or.length === 0 ||
|
||||
condition.$or.some((c) => this.isMatch(c))) &&
|
||||
(!condition.$not || !this.isMatch(condition.$not))
|
||||
)
|
||||
}
|
||||
|
||||
@@ -72,7 +76,7 @@ export default class CommandHandler extends SessionHandler {
|
||||
this.handleCommand()
|
||||
|
||||
const response = stages
|
||||
.filter((s) => this.isMatch(s))
|
||||
.filter((s) => this.isMatch(s.condition))
|
||||
.reduce((r, s) => ({ ...r, ...this.execute(s) }), {})
|
||||
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user