Skip to content

Commit b67afb4

Browse files
committed
Extend the CLI
1 parent d6fff9b commit b67afb4

File tree

1 file changed

+52
-2
lines changed

1 file changed

+52
-2
lines changed

cli/Main.hs

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,47 @@ isDeprecated anns =
8181
isInternal :: ModuleName -> Bool
8282
isInternal x = "Internal" `isInfixOf` x
8383

84-
main :: IO ()
85-
main = do
84+
mainSingle :: [String] -> IO ()
85+
mainSingle args = do
86+
when (length args < 2) $ fail "Need a target and a revision."
87+
let target = args !! 0
88+
rev1 = args !! 1
89+
(Just file1) <- checkoutAndGenerateHoogleFile target rev1
90+
putStrLn $ unwords ["File for", rev1, ":", file1]
91+
api1 <-
92+
fileToLines file1
93+
& Stream.fold (haddockParseFold Added Added Added)
94+
& fmap
95+
(mapAPITags
96+
(mapAttachment (DRight . parseDoc))
97+
(mapAttachment (DRight . parseDoc))
98+
(mapAttachment (DRight . parseDoc)))
99+
step "Printing API"
100+
let elems =
101+
[ ELClasses
102+
, ELDataTypes True
103+
, ELFixities
104+
, ELInstances True
105+
, ELNewTypes True
106+
, ELPatterns
107+
, ELTypeAliases
108+
, ELFunctions
109+
]
110+
let isDeprecatedInRight (Tagged (Attach (DRight anns) _) _) =
111+
isDeprecated anns
112+
isDeprecatedInRight (Tagged (Attach (DBoth _ anns) _) _) =
113+
isDeprecated anns
114+
isDeprecatedInRight _ = False
115+
116+
let apiFiltered =
117+
Map.filterWithKey
118+
(\k v -> not (isInternal k) && not (isDeprecatedInRight v))
119+
api1
120+
121+
putStrLn $ prettyAPI elems apiFiltered
122+
123+
mainDiff :: [String] -> IO ()
124+
mainDiff args = do
86125
args <- getArgs
87126
when (length args < 3) $ fail "Need a target and 2 revisions to compare."
88127
let target = args !! 0
@@ -136,6 +175,17 @@ main = do
136175

137176
putStrLn $ prettyAPI elems diff
138177

178+
main :: IO ()
179+
main = do
180+
args <- getArgs
181+
when (length args < 1) $ fail "Need a mode. [single] or [diff]."
182+
let mode = args !! 0
183+
case mode of
184+
"single" -> mainSingle (tail args)
185+
"diff" -> mainDiff (tail args)
186+
_ -> error "Improper mode."
187+
188+
139189
-- TODO:
140190

141191
-- Deprecated in previous release but not in this release

0 commit comments

Comments
 (0)