5 import System.Environment
7 import System.Console.GetOpt
19 "Usage: hpc COMMAND ...\n\n" ++
20 section "Commands" help ++
21 section "Reporting Coverage" reporting ++
22 section "Processing Coverage files" processing ++
23 section "Coverage Overlays" overlays ++
24 section "Others" other ++
28 reporting = ["report","markup"]
29 overlays = ["overlay","draft"]
30 processing = ["sum","combine","map"]
34 (concat [help,reporting,processing,overlays])
37 section :: String -> [String] -> String
39 section msg cmds = msg ++ ":\n"
40 ++ unlines [ take 14 (" " ++ cmd ++ repeat ' ') ++ summary hook
46 dispatch :: [String] -> IO ()
50 dispatch (txt:args0) = do
51 case lookup txt hooks' of
52 Just plugin -> parse plugin args0
53 _ -> parse help_plugin (txt:args0)
56 case getOpt Permute (options plugin []) args of
57 (_,_,errs) | not (null errs)
58 -> do putStrLn "hpc failed:"
59 sequence [ putStr (" " ++ err)
66 let flags = final_flags plugin
69 implementation plugin flags ns
76 ------------------------------------------------------------------------------
91 hooks' :: [(String, Plugin)]
92 hooks' = [ (name hook,hook) | hook <- hooks ]
94 ------------------------------------------------------------------------------
97 help_plugin = Plugin { name = "help"
98 , usage = "[<HPC_COMMAND>]"
99 , summary = "Display help for hpc or a single command"
100 , options = help_options
101 , implementation = help_main
102 , init_flags = default_flags
103 , final_flags = default_final_flags
106 help_main :: Flags -> [String] -> IO ()
110 help_main _ (sub_txt:_) = do
111 case lookup sub_txt hooks' of
113 putStrLn $ "no such hpc command : " ++ sub_txt
116 command_usage plugin'
119 help_options :: FlagOptSeq
122 ------------------------------------------------------------------------------
124 version_plugin :: Plugin
125 version_plugin = Plugin { name = "version"
127 , summary = "Display version for hpc"
129 , implementation = version_main
130 , init_flags = default_flags
131 , final_flags = default_final_flags
134 version_main :: Flags -> [String] -> IO ()
135 version_main _ _ = putStrLn $ "hpc tools, version 0.6"
138 ------------------------------------------------------------------------------