Add switch to display all term results

This commit is contained in:
Joshua Clayton 2016-05-07 16:18:49 -04:00
parent 4fc984ce75
commit cb6eb12af4

View File

@ -9,6 +9,7 @@ import Unused.CLI (SearchRunner(..), executeSearch, printParseError, printSearch
data Options = Options data Options = Options
{ oSearchRunner :: SearchRunner { oSearchRunner :: SearchRunner
, oAllOccurrencesAndFiles :: Bool
} }
main :: IO () main :: IO ()
@ -34,17 +35,18 @@ withInfo :: Parser a -> String -> ParserInfo a
withInfo opts desc = info (helper <*> opts) $ progDesc desc withInfo opts desc = info (helper <*> opts) $ progDesc desc
optionFilters :: Options -> (ParseResponse -> ParseResponse) optionFilters :: Options -> (ParseResponse -> ParseResponse)
optionFilters _ = optionFilters o =
foldl1 (.) filters foldl1 (.) filters
where where
filters = filters =
[ withOneOccurrence . withOneFile [ if oAllOccurrencesAndFiles o then id else withOneOccurrence . withOneFile
] ]
parseOptions :: Parser Options parseOptions :: Parser Options
parseOptions = parseOptions =
Options Options
<$> parseSearchRunner <$> parseSearchRunner
<*> parseDisplayAllMatches
parseSearchRunner :: Parser SearchRunner parseSearchRunner :: Parser SearchRunner
parseSearchRunner = parseSearchRunner =
@ -52,3 +54,9 @@ parseSearchRunner =
short 'P' short 'P'
<> long "no-progress" <> long "no-progress"
<> help "Don't display progress during analysis" <> help "Don't display progress during analysis"
parseDisplayAllMatches :: Parser Bool
parseDisplayAllMatches = switch $
short 'a'
<> long "all"
<> help "Display all files and occurrences"