From 0900b9b41bc85926b2b5e28b7113f61a8e1f49f2 Mon Sep 17 00:00:00 2001 From: Gabriel Horner Date: Thu, 5 Mar 2026 10:31:39 -0500 Subject: [PATCH] enhance: graph list displays current graph like git and npm. Also remove confusing GRAPH header and make validate consistent like other read graph commands --- .gitignore | 1 + src/main/logseq/cli/commands.cljs | 6 ++---- src/main/logseq/cli/format.cljs | 26 ++++++++++++++++++-------- src/test/logseq/cli/format_test.cljs | 23 +++++++++++++++++++++++ 4 files changed, 44 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 888c1ce302..c1a46b6f3b 100644 --- a/.gitignore +++ b/.gitignore @@ -45,6 +45,7 @@ resources/electron.js /libs/dist/ charlie/ .vscode +/.claude /.preprocessor-cljs docker android/app/src/main/assets/capacitor.plugin.json diff --git a/src/main/logseq/cli/commands.cljs b/src/main/logseq/cli/commands.cljs index 70c1b0dd58..5e21a2033d 100644 --- a/src/main/logseq/cli/commands.cljs +++ b/src/main/logseq/cli/commands.cljs @@ -174,7 +174,8 @@ (:help opts) (command-core/help-result cmd-summary) - (and (#{:graph-create :graph-switch :graph-remove :graph-validate} command) + ;; Require graphs when writing to graph + (and (#{:graph-create :graph-switch :graph-remove :graph-import} command) (not (seq graph))) (missing-graph-result summary) @@ -257,9 +258,6 @@ (and (= command :graph-import) (not (seq (:input opts)))) (missing-input-result summary) - (and (= command :graph-import) (not (seq (:graph opts)))) - (missing-graph-result summary) - (and (= command :graph-import) (not (contains? (graph-command/import-export-types) (graph-command/normalize-import-export-type (:type opts))))) diff --git a/src/main/logseq/cli/format.cljs b/src/main/logseq/cli/format.cljs index 26034802dc..4d267f083e 100644 --- a/src/main/logseq/cli/format.cljs +++ b/src/main/logseq/cli/format.cljs @@ -79,8 +79,9 @@ (defn- format-counted-table [headers rows] - (str (render-table headers rows) - "\n" + (str (if headers + (str (render-table headers rows) "\n") + (str (string/join "\n" (map (comp string/trimr first) rows)) "\n")) "Count: " (count rows))) @@ -215,10 +216,19 @@ (mapv #(format-list-property-row % include-ident? now-ms) items)))) (defn- format-graph-list - [graphs] - (format-counted-table - ["GRAPH"] - (mapv (fn [graph] [graph]) (or graphs [])))) + [graphs current-graph] + (let [graphs (or graphs []) + has-current? (and (seq current-graph) + (some #(= % current-graph) graphs))] + (format-counted-table + nil + (mapv (fn [graph] + [(if has-current? + (if (= graph current-graph) + (str "* " graph) + (str " " graph)) + graph)]) + graphs)))) (defn- format-server-list [servers] @@ -478,12 +488,12 @@ (string/join "\n" (into [header] check-lines)))) (defn- ->human - [{:keys [status data error command context]} {:keys [now-ms]}] + [{:keys [status data error command context]} {:keys [now-ms graph]}] (let [now-ms (or now-ms (js/Date.now))] (case status :ok (case command - :graph-list (format-graph-list (:graphs data)) + :graph-list (format-graph-list (:graphs data) graph) :graph-info (format-graph-info data now-ms) (:graph-create :graph-switch :graph-remove :graph-validate) (format-graph-action command context) diff --git a/src/test/logseq/cli/format_test.cljs b/src/test/logseq/cli/format_test.cljs index ef517ab758..ca46565244 100644 --- a/src/test/logseq/cli/format_test.cljs +++ b/src/test/logseq/cli/format_test.cljs @@ -61,6 +61,29 @@ {:output-format nil})] (is (= "Found 1 entity with errors:\n({:entity {:db/id 1}})\n" result))))) +(deftest test-human-output-graph-list + (testing "graph list without current graph shows plain list" + (let [result (format/format-result {:status :ok + :command :graph-list + :data {:graphs ["alpha" "beta"]}} + {:output-format nil})] + (is (= (str "alpha\n" + "beta\n" + "Count: 2") + result)))) + + (testing "graph list with current graph marks it with * and indents others" + (let [result (format/format-result {:status :ok + :command :graph-list + :data {:graphs ["alpha" "beta" "gamma"]}} + {:output-format nil + :graph "beta"})] + (is (= (str " alpha\n" + "* beta\n" + " gamma\n" + "Count: 3") + result))))) + (deftest test-human-output-list-page (testing "list page renders a table with count" (let [result (format/format-result {:status :ok