Skip to content

Commit

Permalink
Use opts under org.babashka.cli ns
Browse files Browse the repository at this point in the history
  • Loading branch information
Sohalt committed Mar 21, 2024
1 parent 38f5c16 commit 00e4a2a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
16 changes: 8 additions & 8 deletions src/babashka/cli.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -327,14 +327,14 @@
error-fn*))
[opt shell cmdline] args
_ (case opt
"--babashka.cli/completion-snippet"
"--org.babashka.cli/completion-snippet"
(if-let [command-name (get-in opts [:completion :command])]
(do (print-completion-shell-snippet (keyword shell) command-name)
(System/exit 0))
(binding [*out* *err*]
(println "Need `:completion {:command \"<name>\"}` in opts to support shell completions")
(println "Need `:completion {:command \"<name>\"}` in `opts` to support shell completions")
(System/exit 1)))
"--babashka.cli/complete"
"--org.babashka.cli/complete"
(do (print-opts-completions (keyword shell) opts cmdline)
(System/exit 0))
:noop)
Expand Down Expand Up @@ -715,16 +715,16 @@
(case type
:bash (format "_babashka_cli_dynamic_completion()
{
source <( \"$1\" --babashka.cli/complete \"bash\" \"${COMP_WORDS[*]// / }\" )
source <( \"$1\" --org.babashka.cli/complete \"bash\" \"${COMP_WORDS[*]// / }\" )
}
complete -o nosort -F _babashka_cli_dynamic_completion %s
" program-name)
:zsh (format "#compdef %s
source <( \"${words[1]}\" --babashka.cli/complete \"zsh\" \"${words[*]// / }\" )
source <( \"${words[1]}\" --org.babashka.cli/complete \"zsh\" \"${words[*]// / }\" )
" program-name)
:fish (format "function _babashka_cli_dynamic_completion
set --local COMP_LINE (commandline --cut-at-cursor)
%s --babashka.cli/complete fish $COMP_LINE
%s --org.babashka.cli/complete fish $COMP_LINE
end
complete --command %s --no-files --arguments \"(_babashka_cli_dynamic_completion)\"
" program-name program-name)))
Expand Down Expand Up @@ -818,9 +818,9 @@ complete --command %s --no-files --arguments \"(_babashka_cli_dynamic_completion
(let [command-name (get-in opts [:completion :command])
[opt shell cmdline] args]
(case opt
"--babashka.cli/completion-snippet"
"--org.babashka.cli/completion-snippet"
(print-completion-shell-snippet (keyword shell) command-name)
"--babashka.cli/complete"
"--org.babashka.cli/complete"
(print-dispatch-completions (keyword shell) tree cmdline)
(let [{:as res :keys [cmd-info error available-commands]}
(dispatch-tree' tree args opts)
Expand Down
12 changes: 6 additions & 6 deletions test/babashka/cli/completion_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@

(deftest dispatch-completion-test
(when-not (fs/windows?)
(is (= (slurp (io/resource "resources/completion/completion.zsh")) (with-out-str (cli/dispatch cmd-table ["--babashka.cli/completion-snippet" "zsh"] {:completion {:command "myprogram"}})))) ;
(is (= (slurp (io/resource "resources/completion/completion.bash")) (with-out-str (cli/dispatch cmd-table ["--babashka.cli/completion-snippet" "bash"] {:completion {:command "myprogram"}}))))
(is (= (slurp (io/resource "resources/completion/completion.fish")) (with-out-str (cli/dispatch cmd-table ["--babashka.cli/completion-snippet" "fish"] {:completion {:command "myprogram"}}))))
(is (= (slurp (io/resource "resources/completion/completion.zsh")) (with-out-str (cli/dispatch cmd-table ["--org.babashka.cli/completion-snippet" "zsh"] {:completion {:command "myprogram"}})))) ;
(is (= (slurp (io/resource "resources/completion/completion.bash")) (with-out-str (cli/dispatch cmd-table ["--org.babashka.cli/completion-snippet" "bash"] {:completion {:command "myprogram"}}))))
(is (= (slurp (io/resource "resources/completion/completion.fish")) (with-out-str (cli/dispatch cmd-table ["--org.babashka.cli/completion-snippet" "fish"] {:completion {:command "myprogram"}}))))

(is (= "compadd -- foo\n" (with-out-str (cli/dispatch cmd-table ["--babashka.cli/complete" "zsh" "myprogram f"] {:completion {:command "myprogram"}}))))
(is (= "COMPREPLY+=( \"foo\" )\n" (with-out-str (cli/dispatch cmd-table ["--babashka.cli/complete" "bash" "myprogram f "] {:completion {:command "myprogram"}}))))
(is (= "foo\n" (with-out-str (cli/dispatch cmd-table ["--babashka.cli/complete" "fish" "myprogram f "] {:completion {:command "myprogram"}}))))))
(is (= "compadd -- foo\n" (with-out-str (cli/dispatch cmd-table ["--org.babashka.cli/complete" "zsh" "myprogram f"] {:completion {:command "myprogram"}}))))
(is (= "COMPREPLY+=( \"foo\" )\n" (with-out-str (cli/dispatch cmd-table ["--org.babashka.cli/complete" "bash" "myprogram f "] {:completion {:command "myprogram"}}))))
(is (= "foo\n" (with-out-str (cli/dispatch cmd-table ["--org.babashka.cli/complete" "fish" "myprogram f "] {:completion {:command "myprogram"}}))))))
2 changes: 1 addition & 1 deletion test/resources/completion/completion.bash
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
_babashka_cli_dynamic_completion()
{
source <( "$1" --babashka.cli/complete "bash" "${COMP_WORDS[*]// / }" )
source <( "$1" --org.babashka.cli/complete "bash" "${COMP_WORDS[*]// / }" )
}
complete -o nosort -F _babashka_cli_dynamic_completion myprogram
2 changes: 1 addition & 1 deletion test/resources/completion/completion.fish
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function _babashka_cli_dynamic_completion
set --local COMP_LINE (commandline --cut-at-cursor)
myprogram --babashka.cli/complete fish $COMP_LINE
myprogram --org.babashka.cli/complete fish $COMP_LINE
end
complete --command myprogram --no-files --arguments "(_babashka_cli_dynamic_completion)"
2 changes: 1 addition & 1 deletion test/resources/completion/completion.zsh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#compdef myprogram
source <( "${words[1]}" --babashka.cli/complete "zsh" "${words[*]// / }" )
source <( "${words[1]}" --org.babashka.cli/complete "zsh" "${words[*]// / }" )

0 comments on commit 00e4a2a

Please sign in to comment.