mirror of
https://github.com/logseq/logseq.git
synced 2026-04-24 14:14:55 +00:00
fix: commands with required arguments
failing w/ confusing stacktraces. Also exit correctly when a nonexistent graph is given
This commit is contained in:
committed by
Gabriel Horner
parent
a6974021ce
commit
35c2952f6b
14
deps/cli/src/logseq/cli.cljs
vendored
14
deps/cli/src/logseq/cli.cljs
vendored
@@ -66,22 +66,22 @@
|
||||
:fn (lazy-load-fn 'logseq.cli.commands.graph/list-graphs)}
|
||||
{:cmds ["show"] :desc "Show DB graph(s) info"
|
||||
:fn (lazy-load-fn 'logseq.cli.commands.graph/show-graph)
|
||||
:args->opts [:graphs] :coerce {:graphs []}}
|
||||
:args->opts [:graphs] :coerce {:graphs []} :require [:graphs]}
|
||||
{:cmds ["search"]
|
||||
:fn (lazy-load-fn 'logseq.cli.commands.search/search)
|
||||
:desc "Search current DB graph"
|
||||
:args->opts [:search-terms] :coerce {:search-terms []}
|
||||
:args->opts [:search-terms] :coerce {:search-terms []} :require [:search-terms]
|
||||
:spec cli-spec/search}
|
||||
{:cmds ["query"] :desc "Query DB graph(s)"
|
||||
:fn (lazy-load-fn 'logseq.cli.commands.query/query)
|
||||
:args->opts [:graph :args] :coerce {:args []} :no-keyword-opts true
|
||||
:args->opts [:graph :args] :coerce {:args []} :no-keyword-opts true :require [:graph :args]
|
||||
:spec cli-spec/query}
|
||||
{:cmds ["export-edn"] :desc "Export DB graph as EDN"
|
||||
:fn (lazy-load-fn 'logseq.cli.commands.export-edn/export)
|
||||
:args->opts [:graph]
|
||||
:args->opts [:graph] :require [:graph]
|
||||
:spec cli-spec/export-edn}
|
||||
{:cmds ["help"] :fn command-help :desc "Print a command's help"
|
||||
:args->opts [:command]}
|
||||
:args->opts [:command] :require [:command]}
|
||||
{:cmds []
|
||||
:spec default-spec
|
||||
:fn default-command}])
|
||||
@@ -101,7 +101,9 @@
|
||||
{:error-fn (fn [{:keys [cause msg option] type' :type :as data}]
|
||||
(if (and (= :org.babashka/cli type')
|
||||
(= :require cause))
|
||||
(println "Error: Command missing required option" option)
|
||||
(println "Error: Command missing required"
|
||||
(if (get-in data [:spec option]) "option" "argument")
|
||||
option)
|
||||
(throw (ex-info msg data)))
|
||||
(js/process.exit 1))})
|
||||
(catch ^:sci/error js/Error e
|
||||
|
||||
@@ -21,4 +21,4 @@
|
||||
(fs/writeFileSync (:file options)
|
||||
(with-out-str (pprint/pprint export-map))))
|
||||
(pprint/pprint export-map)))
|
||||
(println "Graph" (pr-str graph) "does not exist")))
|
||||
(cli-util/error "Graph" (pr-str graph) "does not exist")))
|
||||
2
deps/cli/src/logseq/cli/commands/graph.cljs
vendored
2
deps/cli/src/logseq/cli/commands/graph.cljs
vendored
@@ -34,7 +34,7 @@
|
||||
(str "https://github.com/logseq/logseq/commit/" (kv-value :logseq.kv/graph-git-sha))])
|
||||
(d/entity @conn :logseq.kv/import-type)
|
||||
(conj ["Graph imported by" (kv-value :logseq.kv/import-type)])))))
|
||||
(println "Graph" (pr-str graph) "does not exist")))))
|
||||
(cli-util/error "Graph" (pr-str graph) "does not exist")))))
|
||||
|
||||
(defn list-graphs
|
||||
[]
|
||||
|
||||
2
deps/cli/src/logseq/cli/commands/query.cljs
vendored
2
deps/cli/src/logseq/cli/commands/query.cljs
vendored
@@ -82,7 +82,7 @@
|
||||
(when (> (count graphs') 1)
|
||||
(println "Results for graph" (pr-str graph')))
|
||||
(pprint/pprint results))
|
||||
(println "Graph" (pr-str graph') "does not exist")))))
|
||||
(cli-util/error "Graph" (pr-str graph') "does not exist")))))
|
||||
|
||||
(defn query
|
||||
[{{:keys [graph args api-query-token]} :opts :as m}]
|
||||
|
||||
6
deps/cli/src/logseq/cli/util.cljs
vendored
6
deps/cli/src/logseq/cli/util.cljs
vendored
@@ -42,4 +42,10 @@
|
||||
(js/console.log "Make sure the HTTP API Server is turned on."))
|
||||
:else
|
||||
(js/console.error "Error:" err))
|
||||
(js/process.exit 1))
|
||||
|
||||
(defn error
|
||||
"Prints error and then exits"
|
||||
[& strings]
|
||||
(apply println "Error:" strings)
|
||||
(js/process.exit 1))
|
||||
Reference in New Issue
Block a user