6 import System.Environment
8 import System.Console.GetOpt
17 "Usage: hpc COMMAND ...\n\n" ++
18 section "Commands" help ++
19 section "Reporting Coverage" reporting ++
20 section "Processing Coverage files" processing ++
21 section "Others" other ++
25 reporting = ["report","markup"]
26 processing = ["combine"]
30 (concat [help,reporting,processing])
33 section :: String -> [String] -> String
35 section msg cmds = msg ++ ":\n"
36 ++ unlines [ take 14 (" " ++ cmd ++ repeat ' ') ++ summary hook
42 dispatch :: [String] -> IO ()
46 dispatch (txt:args) = do
47 case lookup txt hooks' of
48 Just plugin -> parse plugin
49 _ -> parse help_plugin
52 case getOpt Permute (options plugin) args of
53 (_,_,errs) | not (null errs)
54 -> do putStrLn "hpc failed:"
55 sequence [ putStr (" " ++ err)
62 let flags = foldr (.) (final_flags plugin) o
64 implementation plugin flags ns
69 ------------------------------------------------------------------------------
78 hooks' = [ (name hook,hook) | hook <- hooks ]
80 ------------------------------------------------------------------------------
82 help_plugin = Plugin { name = "help"
83 , usage = "[<HPC_COMMAND>]"
84 , summary = "Display help for hpc or a single command."
85 , options = help_options
86 , implementation = help_main
87 , init_flags = default_flags
88 , final_flags = default_final_flags
91 help_main flags [] = do
94 help_main flags (sub_txt:_) = do
95 case lookup sub_txt hooks' of
97 putStrLn $ "no such hpc command : " ++ sub_txt
100 command_usage plugin'
105 ------------------------------------------------------------------------------
107 version_plugin = Plugin { name = "version"
109 , summary = "Display version for hpc"
111 , implementation = version_main
112 , init_flags = default_flags
113 , final_flags = default_final_flags
116 version_main _ _ = putStrLn $ "hpc tools, version 0.5-dev"
119 ------------------------------------------------------------------------------