imported fquery-0.2
[fquery.git] / Adelie / QList.hs
blobc66b5a5df5971ad7f5417f49c0fce314fadfbf36
1 -- QList.hs
2 --
3 -- Module to list the contents of an installed package.
5 module Adelie.QList (
6 ListTypes(..),
8 qList
9 ) where
11 import Adelie.Contents
12 import Adelie.Portage
13 import Adelie.Pretty
15 data ListTypes
16 = ListDirs
17 | ListFiles
18 | ListLinks
19 | ListAll
20 deriving Eq
22 ----------------------------------------------------------------
24 qList :: ListTypes -> [String] -> IO ()
25 qList types args = mapM_ (list puts) =<< findInstalledPackages args
26 where
27 puts = case types of
28 ListDirs -> putsD
29 ListFiles -> putsF
30 ListLinks -> putsL
31 otherwise -> putsA
33 list puts catname = do
34 putStr "Contents of " >> putCatNameLn catname
35 readContents puts contents ()
36 putChar '\n'
37 where contents = contentsFromCatName catname
39 ----------------------------------------------------------------
41 putsA, putsD, putsF, putsL :: Contents -> () -> IO (Bool, ())
43 putsA (Obj o _ _) _ = putStrLn o >> return (False, ())
44 putsA c _ = putContentsLn c >> return (False, ())
46 putsD c@(Dir d) _ = putContentsLn c >> return (False, ())
47 putsD _ _ = return (False, ())
49 putsF (Obj o _ _) _ = putStrLn o >> return (False, ())
50 putsF _ _ = return (False, ())
52 putsL c@(Sym _ _ _)_= putContentsLn c >> return (False, ())
53 putsL _ _ = return (False, ())