6 import System.Environment
8 import System.Console.GetOpt
20 "Usage: hpc COMMAND ...\n\n" ++
21 section "Commands" help ++
22 section "Reporting Coverage" reporting ++
23 section "Processing Coverage files" processing ++
24 section "Coverage Overlays" overlays ++
25 section "Others" other ++
29 reporting = ["report","markup"]
30 overlays = ["overlay","draft"]
31 processing = ["sum","combine","map"]
35 (concat [help,reporting,processing,overlays])
38 section :: String -> [String] -> String
40 section msg cmds = msg ++ ":\n"
41 ++ unlines [ take 14 (" " ++ cmd ++ repeat ' ') ++ summary hook
47 dispatch :: [String] -> IO ()
51 dispatch (txt:args) = do
52 case lookup txt hooks' of
53 Just plugin -> parse plugin args
54 _ -> parse help_plugin (txt:args)
57 case getOpt Permute (options plugin []) args of
58 (_,_,errs) | not (null errs)
59 -> do putStrLn "hpc failed:"
60 sequence [ putStr (" " ++ err)
67 let flags = final_flags plugin
70 implementation plugin flags ns
75 ------------------------------------------------------------------------------
89 hooks' = [ (name hook,hook) | hook <- hooks ]
91 ------------------------------------------------------------------------------
93 help_plugin = Plugin { name = "help"
94 , usage = "[<HPC_COMMAND>]"
95 , summary = "Display help for hpc or a single command"
96 , options = help_options
97 , implementation = help_main
98 , init_flags = default_flags
99 , final_flags = default_final_flags
102 help_main flags [] = do
105 help_main flags (sub_txt:_) = do
106 case lookup sub_txt hooks' of
108 putStrLn $ "no such hpc command : " ++ sub_txt
111 command_usage plugin'
116 ------------------------------------------------------------------------------
118 version_plugin = Plugin { name = "version"
120 , summary = "Display version for hpc"
122 , implementation = version_main
123 , init_flags = default_flags
124 , final_flags = default_final_flags
127 version_main _ _ = putStrLn $ "hpc tools, version 0.6"
130 ------------------------------------------------------------------------------