Skip to content

Commit d7f7dbe

Browse files
fix(cli): fix pluralization of import/export messages
also fix export :classes having wrong count
1 parent 0bc0892 commit d7f7dbe

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

deps/cli/src/logseq/cli/commands/export_edn.cljs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
(= :graph (:export-type options))
1616
(assoc :graph-options (dissoc options :file :export-type :graph))))
1717
file (or (:file options) (str graph "_" (quot (common-util/time-ms) 1000) ".edn"))]
18-
(println "Exported" (count (:properties export-map)) "properties,"
19-
(count (:properties export-map)) "classes and"
20-
(count (:pages-and-blocks export-map)) "pages to" file)
18+
(println (str "Exported " (cli-util/summarize-build-edn export-map) " to " file))
2119
(fs/writeFileSync file
2220
(with-out-str (pprint/pprint export-map))))
2321
(cli-util/error "Graph" (pr-str graph) "does not exist")))

deps/cli/src/logseq/cli/commands/import_edn.cljs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
[promesa.core :as p]))
1111

1212
(defn- print-success [import-map]
13-
(println "Imported" (count (:properties import-map)) "properties,"
14-
(count (:classes import-map)) "classes and"
15-
(count (:pages-and-blocks import-map)) "pages!"))
13+
(println (str "Imported " (cli-util/summarize-build-edn import-map) "!")))
1614

1715
(defn- api-import [api-server-token import-map]
1816
(-> (p/let [resp (cli-util/api-fetch api-server-token "logseq.cli.import_edn" [(sqlite-util/transit-write import-map)])]

deps/cli/src/logseq/cli/util.cljs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(ns ^:node-only logseq.cli.util
22
"CLI only util fns"
3-
(:require ["path" :as node-path]
4-
["fs" :as fs]
3+
(:require ["fs" :as fs]
4+
["path" :as node-path]
55
[clojure.string :as string]
66
[logseq.cli.common.graph :as cli-common-graph]
77
[logseq.db.common.sqlite :as common-sqlite]
@@ -67,4 +67,16 @@
6767
"Prints error and then exits"
6868
[& strings]
6969
(apply println "Error:" strings)
70-
(js/process.exit 1))
70+
(js/process.exit 1))
71+
72+
(defn summarize-build-edn
73+
"Given a sqlite.build EDN map, returns a string summarizing what is transacted"
74+
[edn-map]
75+
(let [pluralize (fn pluralize [word num]
76+
(if (= 1 num)
77+
word
78+
(get {"property" "properties"
79+
"class" "classes"} word (str word "s"))))]
80+
(str (count (:properties edn-map)) " " (pluralize "property" (count (:properties edn-map))) ", "
81+
(count (:classes edn-map)) " " (pluralize "class" (count (:classes edn-map))) " and "
82+
(count (:pages-and-blocks edn-map)) " " (pluralize "page" (count (:pages-and-blocks edn-map))))))

0 commit comments

Comments
 (0)