From 618005bf109c96893723ca12655fde38525780a0 Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Mon, 16 Oct 2023 13:25:07 +0200 Subject: add `--sort` to `list` --- app/Main.hs | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'app/Main.hs') diff --git a/app/Main.hs b/app/Main.hs index 961fb99..e95d5f7 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -258,6 +258,22 @@ -- Additionally using `--reversed`, the order will be reversed. -- -- @topic options +-- +-- COMMENT `anissue list` now supports `--sort` which allows sorting by tags. +-- To facilitate the first use-case, sorting by creation, an internal tag +-- `@createdAt` has been added. Reversing is possible, ie. `--sort +-- '-@createdAt'` +-- +-- Supposing we want to go this direction, I feel like all of the use-cases can +-- be implemented using internal tags and adding support for a couple of data +-- types within String-valued tags. (Sorting by `@createdAt` currently only +-- works because date-based ordering coincides with string-based ordering on +-- the used `YYYY-MM-DD` format.) +-- +-- What do you think? +-- +-- PS. Nothing prevents us later to extend functionality by special cases, +-- should we dislike an internal `@title` tag. -- TODO Add command for (re)generating the cache -- @@ -334,6 +350,8 @@ import Issue (Issue (..)) import Issue qualified as I import Issue.Filter (Filter) import Issue.Filter qualified as I +import Issue.Sort (Sort) +import Issue.Sort qualified as I import Issue.Tag qualified as I import Options.Applicative ((<**>)) import Options.Applicative qualified as O @@ -368,7 +386,8 @@ internalTagsFlag = data Command = List { files :: [String], - filters :: [Filter] + filters :: [Filter], + sort :: [Sort] } | Show { id :: String, @@ -390,6 +409,7 @@ listCmd = List <$> filesArg <*> I.filterArg + <*> I.sortArg showCmd :: O.Parser Command showCmd = @@ -406,7 +426,7 @@ idArg = ( O.metavar "ID" <> O.completer ( O.listIOCompleter $ - catMaybes . map I.id <$> listIssues [] [] + catMaybes . map I.id <$> listIssues [] [] [] ) ) @@ -430,8 +450,8 @@ die s = do main :: IO () main = do O.execParser (O.info (options <**> O.helper) O.idm) >>= \case - Options {internalTags, command = List {filters, files}} -> do - issues <- listIssues filters files + Options {internalTags, command = List {sort, filters, files}} -> do + issues <- listIssues sort filters files putDoc . P.vsep $ map ( \issue -> @@ -451,7 +471,7 @@ main = do ) issues Options {command = Show {id, width}} -> do - issues <- listIssues [] [] + issues <- listIssues [] [] [] case find ((==) (Just id) . I.id) issues of Nothing -> die (printf "no issue with id `%s'\n" id) Just issue -> do -- cgit v1.2.3