diff --git a/README.md b/README.md index 2f58334..83f2044 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ A command line tool in Haskell to identify unused code. -![Image of Unused Output](http://i.giphy.com/l39707ITHLsymwSiI.gif) +![Image of Unused Output](http://i.giphy.com/3oEjHGgyV2EDdy1Ogw.gif) ## Using Unused diff --git a/app/Main.hs b/app/Main.hs index cf15c83..2f796af 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -4,13 +4,14 @@ import Options.Applicative import System.IO (hSetBuffering, BufferMode(NoBuffering), stdout) import Unused.Parser (parseLines) import Unused.Types (ParseResponse, RemovalLikelihood(..)) -import Unused.ResponseFilter (withOneOccurrence, withOneFile, withLikelihoods, ignoringPaths) +import Unused.ResponseFilter (withOneOccurrence, withLikelihoods, ignoringPaths) import Unused.CLI (SearchRunner(..), executeSearch, printParseError, printSearchResults, resetScreen, withInterruptHandler) data Options = Options { oSearchRunner :: SearchRunner - , oAllOccurrencesAndFiles :: Bool + , oSingleOccurrenceMatches :: Bool , oLikelihoods :: [RemovalLikelihood] + , oAllLikelihoods :: Bool , oIgnoredPaths :: [String] } @@ -50,17 +51,22 @@ optionFilters o = foldl1 (.) filters where filters = - [ if oAllOccurrencesAndFiles o then id else withOneOccurrence . withOneFile - , withLikelihoods $ oLikelihoods o + [ if oSingleOccurrenceMatches o then withOneOccurrence else id + , withLikelihoods likelihoods , ignoringPaths $ oIgnoredPaths o ] + likelihoods + | oAllLikelihoods o = [High, Medium, Low] + | null (oLikelihoods o) = [High] + | otherwise = oLikelihoods o parseOptions :: Parser Options parseOptions = Options <$> parseSearchRunner - <*> parseDisplayAllMatches + <*> parseDisplaySingleOccurrenceMatches <*> parseLikelihoods + <*> parseAllLikelihoods <*> parseIgnorePaths parseSearchRunner :: Parser SearchRunner @@ -70,15 +76,14 @@ parseSearchRunner = <> long "no-progress" <> help "Don't display progress during analysis" -parseDisplayAllMatches :: Parser Bool -parseDisplayAllMatches = switch $ - short 'a' - <> long "all" - <> help "Display all files and occurrences" +parseDisplaySingleOccurrenceMatches :: Parser Bool +parseDisplaySingleOccurrenceMatches = switch $ + short 's' + <> long "single-occurrence" + <> help "Display only single occurrences" parseLikelihoods :: Parser [RemovalLikelihood] -parseLikelihoods = many $ - parseLikelihood <$> parseLikelihoodOption +parseLikelihoods = many (parseLikelihood <$> parseLikelihoodOption) parseLikelihood :: String -> RemovalLikelihood parseLikelihood "high" = High @@ -92,6 +97,12 @@ parseLikelihoodOption = strOption $ <> long "likelihood" <> help "[Allows multiple] [Allowed: high, medium, low] Display results based on likelihood" +parseAllLikelihoods :: Parser Bool +parseAllLikelihoods = switch $ + short 'a' + <> long "all-likelihoods" + <> help "Display all likelihoods" + parseIgnorePaths :: Parser [String] parseIgnorePaths = many $ strOption $ long "ignore" diff --git a/src/Unused/ResponseFilter.hs b/src/Unused/ResponseFilter.hs index ddf611c..2741d5f 100644 --- a/src/Unused/ResponseFilter.hs +++ b/src/Unused/ResponseFilter.hs @@ -1,8 +1,6 @@ module Unused.ResponseFilter - ( withOneFile - , withOneOccurrence + ( withOneOccurrence , withLikelihoods - , oneFile , oneOccurence , ignoringPaths , isClassOrModule @@ -16,9 +14,6 @@ import Data.List (isInfixOf) import Unused.Regex (matchRegex) import Unused.Types -withOneFile :: ParseResponse -> ParseResponse -withOneFile = applyFilter (const oneFile) - withOneOccurrence :: ParseResponse -> ParseResponse withOneOccurrence = applyFilter (const oneOccurence) @@ -36,9 +31,6 @@ ignoringPaths xs = newMatches = filter (not . matchesPath . tmPath) matchesPath p = any (`isInfixOf` p) xs -oneFile :: TermResults -> Bool -oneFile = (== 1) . totalFileCount - includesLikelihood :: [RemovalLikelihood] -> TermResults -> Bool includesLikelihood l = (`elem` l) . rLikelihood . trRemoval