mirror of
https://github.com/joshuaclayton/unused.git
synced 2024-10-26 13:19:58 +03:00
Rename to AppError and Main.hs code reorganization
This commit is contained in:
parent
07c0fb0d3f
commit
9ddbd0949c
25
app/Main.hs
25
app/Main.hs
@ -28,24 +28,31 @@ data Options = Options
|
||||
, oFromStdIn :: Bool
|
||||
}
|
||||
|
||||
data AppError
|
||||
= TagError TagSearchOutcome
|
||||
| InvalidConfigError [ParseConfigError]
|
||||
|
||||
main :: IO ()
|
||||
main = runProgram =<< execParser (withInfo parseOptions pHeader pDescription pFooter)
|
||||
main = runProgram =<< parseCLI
|
||||
where
|
||||
runProgram options = withRuntime $
|
||||
runExceptT (run options) >>= either renderError return
|
||||
|
||||
parseCLI :: IO Options
|
||||
parseCLI =
|
||||
execParser (withInfo parseOptions pHeader pDescription pFooter)
|
||||
where
|
||||
pHeader = "Unused: Analyze potentially unused code"
|
||||
pDescription = "Unused allows a developer to leverage an existing tags file\
|
||||
\ (located at .git/tags, tags, or tmp/tags) to identify tokens\
|
||||
\ in a codebase that are unused."
|
||||
pFooter = "CLI USAGE: $ unused"
|
||||
|
||||
data LocalizedError = TagError TagSearchOutcome | InvalidConfigError [ParseConfigError]
|
||||
|
||||
renderError :: LocalizedError -> IO ()
|
||||
renderError :: AppError -> IO ()
|
||||
renderError (TagError e) = V.missingTagsFileError e
|
||||
renderError (InvalidConfigError e) = V.invalidConfigError e
|
||||
|
||||
run :: Options -> ExceptT LocalizedError IO ()
|
||||
run :: Options -> ExceptT AppError IO ()
|
||||
run options = do
|
||||
terms' <- withException TagError $ calculateTagInput options
|
||||
languageConfig <- withException InvalidConfigError loadAllConfigurations
|
||||
@ -76,10 +83,6 @@ withCache :: Options -> IO SearchResults -> IO SearchResults
|
||||
withCache Options{ oWithoutCache = True } = id
|
||||
withCache Options{ oWithoutCache = False } = fmap SearchResults . cached "term-matches" . fmap fromResults
|
||||
|
||||
withInfo :: Parser a -> String -> String -> String -> ParserInfo a
|
||||
withInfo opts h d f =
|
||||
info (helper <*> opts) $ header h <> progDesc d <> footer f
|
||||
|
||||
optionFilters :: Options -> (TermMatchSet -> TermMatchSet)
|
||||
optionFilters o =
|
||||
foldl1 (.) filters
|
||||
@ -94,6 +97,10 @@ optionFilters o =
|
||||
| null (oLikelihoods o) = [High]
|
||||
| otherwise = oLikelihoods o
|
||||
|
||||
withInfo :: Parser a -> String -> String -> String -> ParserInfo a
|
||||
withInfo opts h d f =
|
||||
info (helper <*> opts) $ header h <> progDesc d <> footer f
|
||||
|
||||
parseOptions :: Parser Options
|
||||
parseOptions =
|
||||
Options
|
||||
|
Loading…
Reference in New Issue
Block a user