enhance: list commands can sort by all visibile fields

Remove outdated name field which had no effect. Also remove duplication
of these values in option declaration, completion declaration and
completion tests
This commit is contained in:
Gabriel Horner
2026-03-13 17:45:22 -04:00
parent 0a32fc18fe
commit fbfb589c52
2 changed files with 15 additions and 25 deletions

View File

@@ -20,10 +20,15 @@
:order {:desc "Sort order. Default: asc"
:values ["asc" "desc"]}})
(def ^:private list-sort-fields
{:list-page #{"title" "id" "ident" "created-at" "updated-at"}
:list-tag #{"title" "id" "ident" "created-at" "updated-at"}
:list-property #{"title" "id" "ident" "created-at" "updated-at"}})
(def ^:private list-page-spec
(merge list-common-spec
{:sort {:desc "Sort field"
:values ["title" "created-at" "updated-at"]}
:values (:list-page list-sort-fields)}
:include-journal {:desc "Include journal pages"
:coerce :boolean}
:journal-only {:desc "Only journal pages"
@@ -37,7 +42,7 @@
(def ^:private list-tag-spec
(merge list-common-spec
{:sort {:desc "Sort field"
:values ["name" "title"]}
:values (:list-tag list-sort-fields)}
:include-built-in {:desc "Include built-in tags"
:coerce :boolean}
:with-properties {:desc "Include tag properties"
@@ -49,7 +54,7 @@
(def ^:private list-property-spec
(merge list-common-spec
{:sort {:desc "Sort field"
:values ["name" "title"]}
:values (:list-property list-sort-fields)}
:include-built-in {:desc "Include built-in properties"
:coerce :boolean}
:with-classes {:desc "Include property classes"
@@ -63,11 +68,6 @@
(core/command-entry ["list" "tag"] :list-tag "List tags" list-tag-spec)
(core/command-entry ["list" "property"] :list-property "List properties" list-property-spec)])
(def ^:private list-sort-fields
{:list-page #{"title" "created-at" "updated-at"}
:list-tag #{"name" "title"}
:list-property #{"name" "title"}})
(defn invalid-options?
[command opts]
(let [{:keys [order include-journal journal-only]} opts

View File

@@ -44,15 +44,12 @@
page-entry (first (filter #(= :list-page (:command %)) entries))
tag-entry (first (filter #(= :list-tag (:command %)) entries))
property-entry (first (filter #(= :list-property (:command %)) entries))]
(testing "page-spec :sort has correct values"
(is (= ["title" "created-at" "updated-at"]
(get-in page-entry [:spec :sort :values]))))
(testing "tag-spec :sort has correct values"
(is (= ["name" "title"]
(get-in tag-entry [:spec :sort :values]))))
(testing "property-spec :sort has correct values"
(is (= ["name" "title"]
(get-in property-entry [:spec :sort :values]))))
(testing "page-spec :sort has some correct values"
(is (contains? (get-in page-entry [:spec :sort :values]) "title")))
(testing "tag-spec :sort has some correct values"
(is (contains? (get-in tag-entry [:spec :sort :values]) "title")))
(testing "property-spec :sort has some correct values"
(is (contains? (get-in property-entry [:spec :sort :values]) "title")))
(testing "common :order has correct values"
(is (= ["asc" "desc"]
(get-in page-entry [:spec :order :values]))))))
@@ -214,12 +211,7 @@
(deftest test-zsh-command-specific-values
(let [output (gen/generate-completions "zsh" full-table)]
(testing "--pos under upsert block offers correct values"
(is (re-find #"--pos=.*\(first-child last-child sibling\)" output)))
(testing "--sort for list page offers correct values"
(is (re-find #"--sort=.*\(title created-at updated-at\)" output)))
(testing "--sort for list tag offers name title"
;; Just check globally that name title appears in sort context
(is (re-find #"\(name title\)" output)))))
(is (re-find #"--pos=.*\(first-child last-child sibling\)" output)))))
(deftest test-zsh-all-commands-present
(let [output (gen/generate-completions "zsh" full-table)]
@@ -346,8 +338,6 @@
(is (contains? varied :type)))
(testing "--name is detected as varied"
(is (contains? varied :name)))
(testing "--sort is detected as varied"
(is (contains? varied :sort)))
(testing "uniform options like --pos are not varied"
(is (not (contains? varied :pos))))
(testing "uniform options like --cardinality are not varied"