6 import System.Environment
8 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 = ["combine"]
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:args) = do
51 case lookup txt hooks' of
52 Just plugin -> parse plugin
53 _ -> parse help_plugin
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 = foldr (.) (final_flags plugin) o
68 implementation plugin flags ns
73 ------------------------------------------------------------------------------
84 hooks' = [ (name hook,hook) | hook <- hooks ]
86 ------------------------------------------------------------------------------
88 help_plugin = Plugin { name = "help"
89 , usage = "[<HPC_COMMAND>]"
90 , summary = "Display help for hpc or a single command."
91 , options = help_options
92 , implementation = help_main
93 , init_flags = default_flags
94 , final_flags = default_final_flags
97 help_main flags [] = do
100 help_main flags (sub_txt:_) = do
101 case lookup sub_txt hooks' of
103 putStrLn $ "no such hpc command : " ++ sub_txt
106 command_usage plugin'
111 ------------------------------------------------------------------------------
113 version_plugin = Plugin { name = "version"
115 , summary = "Display version for hpc"
117 , implementation = version_main
118 , init_flags = default_flags
119 , final_flags = default_final_flags
122 version_main _ _ = putStrLn $ "hpc tools, version 0.5-dev"
125 ------------------------------------------------------------------------------