diff options
author | Alexander Foremny <aforemny@posteo.de> | 2023-10-16 13:25:07 +0200 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2023-10-16 14:04:08 +0200 |
commit | 618005bf109c96893723ca12655fde38525780a0 (patch) | |
tree | 98aae5a552c8c382550c4dbe9438652d23c6e141 /app/Main.hs | |
parent | 162577ddab4b440f97509f3076c6cd8ff2371059 (diff) |
add `--sort` to `list`
Diffstat (limited to 'app/Main.hs')
-rw-r--r-- | app/Main.hs | 30 |
1 files changed, 25 insertions, 5 deletions
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 |