aboutsummaryrefslogtreecommitdiffstats
path: root/app/Main.hs
diff options
context:
space:
mode:
Diffstat (limited to 'app/Main.hs')
-rw-r--r--app/Main.hs54
1 files changed, 26 insertions, 28 deletions
diff --git a/app/Main.hs b/app/Main.hs
index 44b4242..1afb7a3 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -24,22 +24,11 @@
-- # @original-issue more information on the issue
-- ```
--- TODO Only one issue per comment block
---
--- Only the first TODO/FIXME inside a comment block should be considered
--- as the start of an issue.
-
-- TODO Add support for other keywords
--
-- Additionally to TODO, also FIXME should start an issue. There might
-- be more interesting keywords.
--- TODO Add filter by tags
---
--- Users can filter issues for tags with the option -t/--tag @tag.
---
--- @assigned kirchner@posteo.de
-
-- TODO Generate and show hash for each issue
module Main where
@@ -55,6 +44,8 @@ import Data.String qualified as String
import Data.Text qualified as T
import Issue (Issue (..))
import Issue qualified as I
+import Issue.Filter (Filter)
+import Issue.Filter qualified as I
import Issue.Tag qualified as I
import Options.Applicative ((<**>))
import Options.Applicative qualified as O
@@ -75,10 +66,12 @@ data Options = Options
data Command
= List
- { files :: [String]
+ { files :: [String],
+ filters :: [Filter]
}
| Show
- { files :: [String]
+ { files :: [String],
+ filters :: [Filter]
}
deriving (Show)
@@ -93,10 +86,10 @@ optionsParser :: O.Parser Options
optionsParser = Options <$> commandParser
listCommandParser :: O.Parser Command
-listCommandParser = List <$> filesArg
+listCommandParser = List <$> filesArg <*> I.filterOption
showCommandParser :: O.Parser Command
-showCommandParser = Show <$> filesArg
+showCommandParser = Show <$> filesArg <*> I.filterOption
filesArg :: O.Parser [String]
filesArg = O.many (O.strArgument (O.metavar "FILE" <> O.action "file"))
@@ -108,21 +101,26 @@ main = do
| opts@(List {}) <- options = opts.files
| opts@(Show {}) <- options = opts.files
filePaths <- getFiles files
+ let filters
+ | opts@(List {}) <- options = opts.filters
+ | opts@(Show {}) <- options = opts.filters
issues <-
- catch
- ( fmap Maybe.catMaybes $
- mapM
- (\filename -> catch (fmap Just (getIssues filename)) (forgetGetIssuesExceptions))
- filePaths
- )
- ( \(InvalidTreeGrepperResult e) ->
- do
- hPutStrLn stderr e
- exitWith (ExitFailure 1)
- )
+ filter (I.applyFilter filters)
+ . concat
+ <$> catch
+ ( fmap Maybe.catMaybes $
+ mapM
+ (\filename -> catch (fmap Just (getIssues filename)) (forgetGetIssuesExceptions))
+ filePaths
+ )
+ ( \(InvalidTreeGrepperResult e) ->
+ do
+ hPutStrLn stderr e
+ exitWith (ExitFailure 1)
+ )
case options of
- List _ -> listMatches $ concat issues
- Show _ -> showMatches $ concat issues
+ List {} -> listMatches issues
+ Show {} -> showMatches issues
showMatches :: [Issue] -> IO ()
showMatches issues = do