Skip to content

Commit c5d539c

Browse files
committed
add $ARGUMENTS placeholder for custom commands
1 parent 3734d58 commit c5d539c

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Improved flaky test #150
66
- Obfuscate env vars in /doctor.
77
- Bump clj-otel to 0.2.10
8+
- Add $ARGUMENTS placeholder alias for custom commands.
89

910
## 0.66.1
1011

src/eca/features/commands.clj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,13 @@
127127
(defn ^:private get-custom-command [command args custom-cmds]
128128
(when-let [raw-content (:content (first (filter #(= command (:name %))
129129
custom-cmds)))]
130-
(let [raw-content (string/replace raw-content "$ARGS" (string/join " " args))]
130+
(let [args-joined (string/join " " args)
131+
content-with-args (-> raw-content
132+
(string/replace "$ARGS" args-joined)
133+
(string/replace "$ARGUMENTS" args-joined))]
131134
(reduce (fn [content [i arg]]
132135
(string/replace content (str "$ARG" (inc i)) arg))
133-
raw-content
136+
content-with-args
134137
(map-indexed vector args)))))
135138

136139
(defn ^:private doctor-msg [db config]

test/eca/features/commands_test.clj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,9 @@
2525
(testing "multiple occurrences of the same placeholder are all replaced"
2626
(let [custom [{:name "dup" :content "$ARG1-$ARG1 $ARGS"}]]
2727
(is (= "x-x x y"
28-
(#'f.commands/get-custom-command "dup" ["x" "y"] custom))))))
28+
(#'f.commands/get-custom-command "dup" ["x" "y"] custom)))))
29+
30+
(testing "$ARGUMENTS is supported as alias for $ARGS"
31+
(let [custom [{:name "test" :content "Process $ARGUMENTS here"}]]
32+
(is (= "Process one two here"
33+
(#'f.commands/get-custom-command "test" ["one" "two"] custom))))))

0 commit comments

Comments
 (0)