feat: Filterchains can now be passed inputs and outputs.

This commit is contained in:
Spencer Brower
2024-02-24 11:27:58 -05:00
parent 7ce5f70980
commit aa5c8fe9c9
2 changed files with 51 additions and 5 deletions

View File

@@ -36,9 +36,7 @@ export def "run" [
def "append last" [
items: list
]: list -> list {
let list = $in;
($list | range 0..-2) | append [($list | default [] | last | append $items)]
update (($in | length) - 1) { $in | append $items }
}
export def "cmd filters append" [
@@ -97,8 +95,8 @@ def "filter to-string" []: record<input: list<string> name: string params: table
# Set the input and outputs of a filter chain
export def filterchain [
#input: list<string>
#output: list<string>
--input (-i): list<string>
--output (-o): list<string>
filter: closure
] {
let cmd = $in;
@@ -118,6 +116,22 @@ export def filterchain [
}
}
| do $filter
| if ($input | is-empty | not $in) {
update filters {
update (($in | length) - 1) {
update 0.input $input
}
}
} else { $in }
| if ($output | is-empty | not $in) {
update filters {
update (($in | length) - 1) {
update (($in | length) - 1) {
update output $output
}
}
}
} else { $in }
| update options.chain_filters $original_option
);
}