mirror of
https://github.com/joshuaclayton/unused.git
synced 2024-09-11 04:45:28 +03:00
Search for terms from a tags file
This returns a list of each match, files, and counts based on the current directory.
This commit is contained in:
parent
8931c08f93
commit
1249a0e823
@ -1,6 +1,9 @@
|
||||
module Main where
|
||||
|
||||
import Lib
|
||||
import Unused.TermSearch (search)
|
||||
|
||||
main :: IO ()
|
||||
main = someFunc
|
||||
main = do
|
||||
tokens <- pure . lines =<< getContents
|
||||
results <- pure . concat =<< mapM search tokens
|
||||
putStrLn $ unlines results
|
||||
|
@ -1,6 +0,0 @@
|
||||
module Lib
|
||||
( someFunc
|
||||
) where
|
||||
|
||||
someFunc :: IO ()
|
||||
someFunc = putStrLn "someFunc"
|
24
src/Unused/TermSearch.hs
Normal file
24
src/Unused/TermSearch.hs
Normal file
@ -0,0 +1,24 @@
|
||||
module Unused.TermSearch
|
||||
( search
|
||||
) where
|
||||
|
||||
import System.IO
|
||||
import System.Process
|
||||
|
||||
search :: String -> IO [String]
|
||||
search t = do
|
||||
results <- ag t
|
||||
return $ linesMap prefixTerm results
|
||||
where
|
||||
prefixTerm = ((++) t)
|
||||
|
||||
linesMap :: (String -> String) -> String -> [String]
|
||||
linesMap f =
|
||||
filter empty . map f . lines
|
||||
where
|
||||
empty = ((/=) 0) . length
|
||||
|
||||
ag :: String -> IO String
|
||||
ag t = do
|
||||
(_, results, _) <- readProcessWithExitCode "ag" [t, ".", "-c", "-Q", "--ackmate"] ""
|
||||
return results
|
@ -15,8 +15,9 @@ cabal-version: >=1.10
|
||||
|
||||
library
|
||||
hs-source-dirs: src
|
||||
exposed-modules: Lib
|
||||
exposed-modules: Unused.TermSearch
|
||||
build-depends: base >= 4.7 && < 5
|
||||
, process
|
||||
default-language: Haskell2010
|
||||
|
||||
executable unused
|
||||
|
Loading…
Reference in New Issue
Block a user