mirror of
https://github.com/joshuaclayton/unused.git
synced 2024-08-15 15:50:26 +03:00
Use sensible defaults for the CLI
Why? ==== By default, people want to see an actionable, comprehensive list without having to pass any flags into the program. Previously, to see everything with high likelihood you'd need to provide `-a --likelihood high`. This commit changes the program so that's the default. It also introduces a `--all-likelihoods` flag (shorthand is `-a`) to see everything, so if you want to opt into see it, you can. Finally, this changes `-a` (to see everything) to `-s` (to see only single occurrences, which was the previous default).
This commit is contained in:
parent
56c083097d
commit
8d5e13c89e
@ -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
|
||||
|
||||
|
35
app/Main.hs
35
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"
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user