diff --git a/docs/agent-guide/006-logseq-cli-import-export.md b/docs/agent-guide/006-logseq-cli-import-export.md index f84ab5b0d7..42df290964 100644 --- a/docs/agent-guide/006-logseq-cli-import-export.md +++ b/docs/agent-guide/006-logseq-cli-import-export.md @@ -19,8 +19,8 @@ Related: Builds on docs/agent-guide/004-logseq-cli-verb-subcommands.md and docs/ Prefer graph-scoped subcommands to keep import/export with graph management: -- `logseq graph export --type edn --output [--repo ]` -- `logseq graph export --type sqlite --output [--repo ]` +- `logseq graph export --type edn --file [--repo ]` +- `logseq graph export --type sqlite --file [--repo ]` - `logseq graph import --type edn --input --repo ` - `logseq graph import --type sqlite --input --repo ` diff --git a/docs/cli/logseq-cli.md b/docs/cli/logseq-cli.md index 894e34583a..6254450d39 100644 --- a/docs/cli/logseq-cli.md +++ b/docs/cli/logseq-cli.md @@ -72,7 +72,7 @@ Graph commands: - `graph remove --repo ` - remove a graph - `graph validate --repo ` - validate graph data - `graph info [--repo ]` - show graph metadata (defaults to current graph) -- `graph export --type edn|sqlite --output [--repo ]` - export a graph to EDN or SQLite +- `graph export --type edn|sqlite --file [--repo ]` - export a graph to EDN or SQLite - `graph import --type edn|sqlite --input --repo ` - import a graph from EDN or SQLite (new graph only) For any command that requires `--repo`, if the target graph does not exist, the CLI returns `graph not exists` (except for `graph create`). `graph import` fails if the target graph already exists. @@ -145,7 +145,7 @@ Revision: Output formats: - Global `--output ` applies to all commands -- For `graph export`, `--output` refers to the destination file path. Output formatting is controlled via `:output-format` in config or `LOGSEQ_CLI_OUTPUT`. +- Output formatting is controlled via global `--output`, `:output-format` in config, or `LOGSEQ_CLI_OUTPUT`. - Human output is plain text. List/search commands render tables with a final `Count: N` line. For list and search subcommands, the ID column uses `:db/id` (not UUID). If `:db/ident` exists, an `IDENT` column is included. `list property` includes a dedicated `TYPE` column. Search table columns are `ID` and `TITLE`. Block titles can include multiple lines; multi-line rows align additional lines under the `TITLE` column. Times such as list `UPDATED-AT`/`CREATED-AT` and `graph info` `Created at` are shown in human-friendly relative form. Errors include error codes and may include a `Hint:` line. Use `--output json|edn` for structured output. - For `list property`, `TYPE` is returned in default output (without `--expand`) for human and structured (`json`/`edn`) formats. - `upsert page` and `upsert block` return entity ids in `data.result` for JSON/EDN output, and include ids in human output. @@ -188,7 +188,7 @@ Examples: ```bash node ./dist/logseq.js graph create --repo demo -node ./dist/logseq.js graph export --type edn --output /tmp/demo.edn --repo demo +node ./dist/logseq.js graph export --type edn --file /tmp/demo.edn --repo demo node ./dist/logseq.js graph import --type edn --input /tmp/demo.edn --repo demo-import node ./dist/logseq.js upsert block --target-page TestPage --content "hello world" node ./dist/logseq.js move --uuid --target-page TargetPage diff --git a/src/main/logseq/cli/command/graph.cljs b/src/main/logseq/cli/command/graph.cljs index ccec6d6e9c..d5a646274a 100644 --- a/src/main/logseq/cli/command/graph.cljs +++ b/src/main/logseq/cli/command/graph.cljs @@ -9,7 +9,7 @@ (def ^:private graph-export-spec {:type {:desc "Export type (edn, sqlite)"} - :output {:desc "Output path"}}) + :file {:desc "Export file path"}}) (def ^:private graph-import-spec {:type {:desc "Import type (edn, sqlite)"} @@ -107,7 +107,7 @@ :graph (core/repo->graph repo)}}))) (defn build-export-action - [repo export-type output] + [repo export-type file] (if-not (seq repo) {:ok? false :error {:code :missing-repo @@ -117,7 +117,7 @@ :repo repo :graph (core/repo->graph repo) :export-type export-type - :output output}})) + :file file}})) (defn build-import-action [repo import-type input] @@ -201,9 +201,9 @@ (js/Buffer.from export-result "base64") export-result) format (if (= export-type "sqlite") :sqlite :edn)] - (transport/write-output {:format format :path (:output action) :data data}) + (transport/write-output {:format format :path (:file action) :data data}) {:status :ok - :data {:message (str "wrote " (:output action))}}))) + :data {:message (str "wrote " (:file action))}}))) (defn execute-graph-import [action config] diff --git a/src/main/logseq/cli/commands.cljs b/src/main/logseq/cli/commands.cljs index 560f89a94e..685fd98393 100644 --- a/src/main/logseq/cli/commands.cljs +++ b/src/main/logseq/cli/commands.cljs @@ -82,11 +82,11 @@ :message "input is required"} :summary summary}) -(defn- missing-output-result +(defn- missing-file-result [summary] {:ok? false - :error {:code :missing-output - :message "output is required"} + :error {:code :missing-file + :message "file is required"} :summary summary}) (defn- missing-query-result @@ -248,8 +248,8 @@ (and (= command :graph-export) (not (seq (graph-command/normalize-import-export-type (:type opts))))) (missing-type-result summary) - (and (= command :graph-export) (not (seq (:output opts)))) - (missing-output-result summary) + (and (= command :graph-export) (not (seq (:file opts)))) + (missing-file-result summary) (and (= command :graph-export) (not (contains? (graph-command/import-export-types) @@ -387,7 +387,7 @@ :graph-export (let [export-type (graph-command/normalize-import-export-type (:type options))] - (graph-command/build-export-action repo export-type (:output options))) + (graph-command/build-export-action repo export-type (:file options))) :graph-import (let [import-repo (command-core/resolve-repo (:repo options)) @@ -481,4 +481,4 @@ :schema :source :target :update-tags :update-properties :remove-tags :remove-properties - :export-type :output :import-type :input]))))) + :export-type :file :import-type :input]))))) diff --git a/src/main/logseq/cli/format.cljs b/src/main/logseq/cli/format.cljs index 3658007189..ffa017fcb1 100644 --- a/src/main/logseq/cli/format.cljs +++ b/src/main/logseq/cli/format.cljs @@ -330,8 +330,8 @@ (str "Removed property: " id " (repo: " repo ")"))) (defn- format-graph-export - [{:keys [export-type output]}] - (str "Exported " export-type " to " output)) + [{:keys [export-type file]}] + (str "Exported " export-type " to " file)) (defn- format-graph-import [{:keys [import-type input]}] diff --git a/src/test/logseq/cli/commands_test.cljs b/src/test/logseq/cli/commands_test.cljs index 2a9fd13e7f..97aa3a879a 100644 --- a/src/test/logseq/cli/commands_test.cljs +++ b/src/test/logseq/cli/commands_test.cljs @@ -1183,14 +1183,14 @@ (is (false? (:ok? result))) (is (= :missing-graph (get-in result [:error :code]))))) - (testing "graph export parses with type and output" + (testing "graph export parses with type and file" (let [result (commands/parse-args ["graph" "export" "--type" "edn" - "--output" "export.edn"])] + "--file" "export.edn"])] (is (true? (:ok? result))) (is (= :graph-export (:command result))) (is (= "edn" (get-in result [:options :type]))) - (is (= "export.edn" (get-in result [:options :output]))))) + (is (= "export.edn" (get-in result [:options :file]))))) (testing "graph import parses with type, input, and repo" (let [result (commands/parse-args ["graph" "import" @@ -1204,14 +1204,19 @@ (is (= "demo" (get-in result [:options :repo]))))) (testing "graph export requires type" - (let [result (commands/parse-args ["graph" "export" "--output" "export.edn"])] + (let [result (commands/parse-args ["graph" "export" "--file" "export.edn"])] (is (false? (:ok? result))) (is (= :missing-type (get-in result [:error :code]))))) - (testing "graph export requires output" + (testing "graph export requires file" (let [result (commands/parse-args ["graph" "export" "--type" "edn"])] (is (false? (:ok? result))) - (is (= :missing-output (get-in result [:error :code]))))) + (is (= :missing-file (get-in result [:error :code]))))) + + (testing "graph export accepts global output format and still requires file" + (let [result (commands/parse-args ["graph" "export" "--type" "edn" "--output" "json"])] + (is (false? (:ok? result))) + (is (= :missing-file (get-in result [:error :code]))))) (testing "graph import requires repo" (let [result (commands/parse-args ["graph" "import" @@ -1280,7 +1285,7 @@ (testing "graph export uses config repo" (let [parsed {:ok? true :command :graph-export - :options {:type "edn" :output "export.edn"}} + :options {:type "edn" :file "export.edn"}} result (commands/build-action parsed {:repo "demo"})] (is (true? (:ok? result))) (is (= :graph-export (get-in result [:action :type]))))) @@ -2485,22 +2490,22 @@ :repo "logseq_db_demo" :graph "demo" :export-type "edn" - :output "/tmp/export.edn" + :file "/tmp/export.edn" :allow-missing-graph true} {}) sqlite-result (commands/execute {:type :graph-export :repo "logseq_db_demo" :graph "demo" :export-type "sqlite" - :output "/tmp/export.sqlite" + :file "/tmp/export.sqlite" :allow-missing-graph true} {})] (is (= :ok (:status edn-result))) (is (= :ok (:status sqlite-result))) (is (= "edn" (get-in edn-result [:context :export-type]))) - (is (= "/tmp/export.edn" (get-in edn-result [:context :output]))) + (is (= "/tmp/export.edn" (get-in edn-result [:context :file]))) (is (= "sqlite" (get-in sqlite-result [:context :export-type]))) - (is (= "/tmp/export.sqlite" (get-in sqlite-result [:context :output]))) + (is (= "/tmp/export.sqlite" (get-in sqlite-result [:context :file]))) (is (= [[:thread-api/export-edn false ["logseq_db_demo" {:export-type :graph}]] [:thread-api/export-db-base64 true ["logseq_db_demo"]]] @invoke-calls)) diff --git a/src/test/logseq/cli/format_test.cljs b/src/test/logseq/cli/format_test.cljs index e7b0fa96a6..11c4695525 100644 --- a/src/test/logseq/cli/format_test.cljs +++ b/src/test/logseq/cli/format_test.cljs @@ -207,7 +207,7 @@ (let [result (format/format-result {:status :ok :command :graph-export :context {:export-type "edn" - :output "/tmp/export.edn"}} + :file "/tmp/export.edn"}} {:output-format nil})] (is (= "Exported edn to /tmp/export.edn" result)))) diff --git a/src/test/logseq/cli/integration_test.cljs b/src/test/logseq/cli/integration_test.cljs index 9407093818..31fb08d9f8 100644 --- a/src/test/logseq/cli/integration_test.cljs +++ b/src/test/logseq/cli/integration_test.cljs @@ -2190,7 +2190,7 @@ export-result (run-cli ["--repo" export-graph "graph" "export" "--type" "edn" - "--output" export-path] data-dir cfg-path) + "--file" export-path] data-dir cfg-path) export-payload (parse-json-output export-result) _ (run-cli ["--repo" import-graph "graph" "import" @@ -2229,7 +2229,7 @@ export-result (run-cli ["--repo" export-graph "graph" "export" "--type" "sqlite" - "--output" export-path] data-dir cfg-path) + "--file" export-path] data-dir cfg-path) export-payload (parse-json-output export-result) _ (run-cli ["--repo" import-graph "graph" "import"