fix(cli): fix pluralization of import/export messages

also fix export :classes having wrong count
This commit is contained in:
Gabriel Horner
2025-11-06 16:35:53 -05:00
parent 0bc0892b8a
commit d7f7dbea1d
3 changed files with 17 additions and 9 deletions

View File

@@ -15,9 +15,7 @@
(= :graph (:export-type options))
(assoc :graph-options (dissoc options :file :export-type :graph))))
file (or (:file options) (str graph "_" (quot (common-util/time-ms) 1000) ".edn"))]
(println "Exported" (count (:properties export-map)) "properties,"
(count (:properties export-map)) "classes and"
(count (:pages-and-blocks export-map)) "pages to" file)
(println (str "Exported " (cli-util/summarize-build-edn export-map) " to " file))
(fs/writeFileSync file
(with-out-str (pprint/pprint export-map))))
(cli-util/error "Graph" (pr-str graph) "does not exist")))

View File

@@ -10,9 +10,7 @@
[promesa.core :as p]))
(defn- print-success [import-map]
(println "Imported" (count (:properties import-map)) "properties,"
(count (:classes import-map)) "classes and"
(count (:pages-and-blocks import-map)) "pages!"))
(println (str "Imported " (cli-util/summarize-build-edn import-map) "!")))
(defn- api-import [api-server-token import-map]
(-> (p/let [resp (cli-util/api-fetch api-server-token "logseq.cli.import_edn" [(sqlite-util/transit-write import-map)])]

View File

@@ -1,7 +1,7 @@
(ns ^:node-only logseq.cli.util
"CLI only util fns"
(:require ["path" :as node-path]
["fs" :as fs]
(:require ["fs" :as fs]
["path" :as node-path]
[clojure.string :as string]
[logseq.cli.common.graph :as cli-common-graph]
[logseq.db.common.sqlite :as common-sqlite]
@@ -67,4 +67,16 @@
"Prints error and then exits"
[& strings]
(apply println "Error:" strings)
(js/process.exit 1))
(js/process.exit 1))
(defn summarize-build-edn
"Given a sqlite.build EDN map, returns a string summarizing what is transacted"
[edn-map]
(let [pluralize (fn pluralize [word num]
(if (= 1 num)
word
(get {"property" "properties"
"class" "classes"} word (str word "s"))))]
(str (count (:properties edn-map)) " " (pluralize "property" (count (:properties edn-map))) ", "
(count (:classes edn-map)) " " (pluralize "class" (count (:classes edn-map))) " and "
(count (:pages-and-blocks edn-map)) " " (pluralize "page" (count (:pages-and-blocks edn-map))))))