From 0a39d9038e20bb0f02aaf9e963f088e953471acd Mon Sep 17 00:00:00 2001 From: rcmerci Date: Sun, 29 Mar 2026 21:20:43 +0800 Subject: [PATCH] enhance(cli): update search cmd hint --- src/main/logseq/cli/commands.cljs | 2 +- src/main/logseq/cli/format.cljs | 19 ++++++++++++++----- src/test/logseq/cli/format_test.cljs | 15 +++++++++++++++ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/main/logseq/cli/commands.cljs b/src/main/logseq/cli/commands.cljs index 2d5c774fc5..ca8acb08c9 100644 --- a/src/main/logseq/cli/commands.cljs +++ b/src/main/logseq/cli/commands.cljs @@ -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)) diff --git a/src/main/logseq/cli/format.cljs b/src/main/logseq/cli/format.cljs index add999b7d3..092b7ada59 100644 --- a/src/main/logseq/cli/format.cljs +++ b/src/main/logseq/cli/format.cljs @@ -118,15 +118,24 @@ "Count: " (count rows))) +(defn- missing-search-query-hint + [command] + (case command + :search-block "Use: logseq search block --content " + :search-page "Use: logseq search page --content " + :search-property "Use: logseq search property --content " + :search-tag "Use: logseq search tag --content " + "Use: logseq search --content ")) + (defn- error-hint - [{:keys [code]}] + [{:keys [code]} command] (case code :missing-graph "Use --graph " :missing-repo "Use --graph " :missing-content "Use --content or pass content as args" :missing-tag-name "Use --name " :missing-query "Use --query " - :missing-query-text "Use: logseq search " + :missing-query-text (missing-search-query-hint command) :unknown-query "Use `logseq query list` to see available queries" :ambiguous-tag-name "Retry with --id " :ambiguous-property-name "Retry with --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})))) diff --git a/src/test/logseq/cli/format_test.cljs b/src/test/logseq/cli/format_test.cljs index 9b8562e057..8610010a89 100644 --- a/src/test/logseq/cli/format_test.cljs +++ b/src/test/logseq/cli/format_test.cljs @@ -933,6 +933,21 @@ "Hint: Use --graph ") result)))) + (testing "missing query text uses per-subcommand --content hint" + (doseq [[command hint] + [[:search-block "Use: logseq search block --content "] + [:search-page "Use: logseq search page --content "] + [:search-property "Use: logseq search property --content "] + [:search-tag "Use: logseq search tag --content "]]] + (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