mirror of
https://github.com/logseq/logseq.git
synced 2026-04-24 14:14:55 +00:00
fix(cli): fix pluralization of import/export messages
also fix export :classes having wrong count
This commit is contained in:
@@ -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")))
|
||||
@@ -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)])]
|
||||
|
||||
18
deps/cli/src/logseq/cli/util.cljs
vendored
18
deps/cli/src/logseq/cli/util.cljs
vendored
@@ -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))))))
|
||||
Reference in New Issue
Block a user