enhance(cli): update search cmd hint

This commit is contained in:
rcmerci
2026-03-29 21:20:43 +08:00
parent 1afc0e558c
commit 0a39d9038e
3 changed files with 30 additions and 6 deletions

View File

@@ -266,7 +266,7 @@
(and (#{:search-block :search-page :search-property :search-tag} command)
(not (seq (some-> (:content opts) str string/trim))))
(missing-query-text-result summary)
(assoc (missing-query-text-result summary) :command command)
(and (#{:list-page :list-tag :list-property} command)
(list-command/invalid-options? opts))

View File

@@ -118,15 +118,24 @@
"Count: "
(count rows)))
(defn- missing-search-query-hint
[command]
(case command
:search-block "Use: logseq search block --content <query>"
:search-page "Use: logseq search page --content <query>"
:search-property "Use: logseq search property --content <query>"
:search-tag "Use: logseq search tag --content <query>"
"Use: logseq search <block|page|property|tag> --content <query>"))
(defn- error-hint
[{:keys [code]}]
[{:keys [code]} command]
(case code
:missing-graph "Use --graph <name>"
:missing-repo "Use --graph <name>"
:missing-content "Use --content or pass content as args"
:missing-tag-name "Use --name <tag-name>"
:missing-query "Use --query <edn>"
:missing-query-text "Use: logseq search <block|page|property|tag> <query>"
:missing-query-text (missing-search-query-hint command)
:unknown-query "Use `logseq query list` to see available queries"
:ambiguous-tag-name "Retry with --id <tag-id>"
:ambiguous-property-name "Retry with --id <property-id>"
@@ -145,9 +154,9 @@
candidates)))))
(defn- format-error
[error]
[error command]
(let [{:keys [code message candidates]} error
hint (error-hint error)
hint (error-hint error command)
message* (style/bold-keywords message ["option" "command" "argument"])
candidates* (format-candidates candidates)]
(if (= :graph-validation-failed code)
@@ -755,7 +764,7 @@
(format-doctor (or (get-in data [:status]) :error)
(or (get-in data [:checks])
(get-in error [:checks])))
(format-error error))
(format-error error command))
(pr-str {:status status :data data :error error}))))

View File

@@ -933,6 +933,21 @@
"Hint: Use --graph <name>")
result))))
(testing "missing query text uses per-subcommand --content hint"
(doseq [[command hint]
[[:search-block "Use: logseq search block --content <query>"]
[:search-page "Use: logseq search page --content <query>"]
[:search-property "Use: logseq search property --content <query>"]
[:search-tag "Use: logseq search tag --content <query>"]]]
(let [result (format/format-result {:status :error
:command command
:error {:code :missing-query-text
:message "query text is required"}}
{:output-format nil})]
(is (= (str "Error (missing-query-text): query text is required\n"
"Hint: " hint)
result)))))
(testing "owner mismatch includes ownership hint"
(let [result (format/format-result {:status :error
:command :server-stop