mirror of
https://github.com/logseq/logseq.git
synced 2026-04-24 22:25:01 +00:00
enhance: add append command
Fixes https://test.logseq.com/#/page/689ca670-d93f-4fe0-a262-029d95f8450f
This commit is contained in:
1
deps/cli/.carve/ignore
vendored
1
deps/cli/.carve/ignore
vendored
@@ -5,3 +5,4 @@ logseq.cli.commands.graph/list-graphs
|
||||
logseq.cli.commands.query/query
|
||||
logseq.cli.commands.search/search
|
||||
logseq.cli.commands.export/export
|
||||
logseq.cli.commands.append/append
|
||||
|
||||
1
deps/cli/CHANGELOG.md
vendored
1
deps/cli/CHANGELOG.md
vendored
@@ -1,5 +1,6 @@
|
||||
## 0.2.0
|
||||
* Add export command to export graph as markdown
|
||||
* Add append command to add text to current page
|
||||
* Change export-edn command to default to writing to a file, like the export command
|
||||
* Rename --api-query-token options to --api-server-token
|
||||
* Add descriptions for most commands to explain in-depth usage
|
||||
|
||||
11
deps/cli/README.md
vendored
11
deps/cli/README.md
vendored
@@ -12,7 +12,7 @@ This section assumes you have installed the CLI from npm or via the [dev
|
||||
setup](#setup). If you haven't, substitute `node cli.mjs` for `logseq` e.g.
|
||||
`node.cli.mjs -h`.
|
||||
|
||||
All commands can be used offline or on CI. The `search` command and any command that has an api-server-token option require the [HTTP API Server](https://docs.logseq.com/#/page/local%20http%20server) to be turned on.
|
||||
All commands except for `append` can be used offline or on CI. The `search` command and any command that has an api-server-token option require the [HTTP API Server](https://docs.logseq.com/#/page/local%20http%20server) to be turned on.
|
||||
|
||||
Now let's use it!
|
||||
|
||||
@@ -26,12 +26,13 @@ Options:
|
||||
Commands:
|
||||
list List graphs
|
||||
show Show DB graph(s) info
|
||||
search [options] Search current DB graph
|
||||
search [options] Search DB graph
|
||||
query [options] Query DB graph(s)
|
||||
export [options] Export DB graph as Markdown
|
||||
export-edn [options] Export DB graph as EDN
|
||||
append [options] Appends text to current page
|
||||
help Print a command's help
|
||||
|
||||
|
||||
$ logseq list
|
||||
DB Graphs:
|
||||
db-test
|
||||
@@ -117,6 +118,10 @@ Exported 41 pages to yep_markdown_1756128259.zip
|
||||
# Export DB graph as EDN
|
||||
$ logseq export-edn woot -f woot.edn
|
||||
Exported 16 properties, 16 classes and 36 pages
|
||||
|
||||
# Append text to current page
|
||||
$ logseq append add this text -a my-token
|
||||
Success!
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
4
deps/cli/src/logseq/cli.cljs
vendored
4
deps/cli/src/logseq/cli.cljs
vendored
@@ -95,6 +95,10 @@
|
||||
:fn (lazy-load-fn 'logseq.cli.commands.export-edn/export)
|
||||
:args->opts [:graph] :require [:graph]
|
||||
:spec cli-spec/export-edn}
|
||||
{:cmds ["append"] :desc "Appends text to current page"
|
||||
:fn (lazy-load-fn 'logseq.cli.commands.append/append)
|
||||
:args->opts [:args] :require [:args] :coerce {:args []}
|
||||
:spec cli-spec/append}
|
||||
{:cmds ["help"] :fn help-command :desc "Print a command's help"
|
||||
:args->opts [:command] :require [:command]}
|
||||
{:cmds []
|
||||
|
||||
19
deps/cli/src/logseq/cli/commands/append.cljs
vendored
Normal file
19
deps/cli/src/logseq/cli/commands/append.cljs
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
(ns logseq.cli.commands.append
|
||||
"Command to append to a page"
|
||||
(:require [clojure.string :as string]
|
||||
[logseq.cli.util :as cli-util]
|
||||
[promesa.core :as p]))
|
||||
|
||||
(defn append
|
||||
[{{:keys [api-server-token args]} :opts}]
|
||||
(let [text (string/join " " args)]
|
||||
(-> (p/let [resp (cli-util/api-fetch api-server-token "logseq.app.append_block_in_page" [text nil nil])]
|
||||
(if (= 200 (.-status resp))
|
||||
(p/let [body (.json resp)]
|
||||
(if (.-error body)
|
||||
(cli-util/error (str "Failed to append. Ensure the app is in a specific page.\n"
|
||||
"API Response: "
|
||||
(string/replace (.-error body) "\n" "\\\\n")))
|
||||
(println "Success!")))
|
||||
(cli-util/api-handle-error-response resp)))
|
||||
(p/catch cli-util/command-catch-handler))))
|
||||
10
deps/cli/src/logseq/cli/spec.cljs
vendored
10
deps/cli/src/logseq/cli/spec.cljs
vendored
@@ -35,13 +35,17 @@
|
||||
:title-query {:alias :t
|
||||
:desc "Invoke local query on :block/title"}
|
||||
:api-server-token {:alias :a
|
||||
:desc "API server token to query current graph"}})
|
||||
:desc "API server token to query current graph"}})
|
||||
|
||||
(def search
|
||||
{:api-server-token {:alias :a
|
||||
:desc "API server token to search current graph"}
|
||||
:desc "API server token to search current graph"}
|
||||
:raw {:alias :r
|
||||
:desc "Print raw response"}
|
||||
:limit {:alias :l
|
||||
:default 100
|
||||
:desc "Limit max number of results"}})
|
||||
:desc "Limit max number of results"}})
|
||||
|
||||
(def append
|
||||
{:api-server-token {:alias :a
|
||||
:desc "API server token to modify current graph"}})
|
||||
Reference in New Issue
Block a user