5 import System.Environment
7 import System.Console.GetOpt
18 "Usage: hpc COMMAND ...\n\n" ++
19 section "Commands" help ++
20 section "Reporting Coverage" reporting ++
21 section "Processing Coverage files" processing ++
22 section "Coverage Overlays" overlays ++
23 section "Others" other ++
27 reporting = ["report","markup"]
28 overlays = ["overlay","draft"]
29 processing = ["combine"]
33 (concat [help,reporting,processing,overlays])
36 section :: String -> [String] -> String
38 section msg cmds = msg ++ ":\n"
39 ++ unlines [ take 14 (" " ++ cmd ++ repeat ' ') ++ summary hook
45 dispatch :: [String] -> IO ()
49 dispatch (txt:args) = do
50 case lookup txt hooks' of
51 Just plugin -> parse plugin
52 _ -> parse help_plugin
55 case getOpt Permute (options plugin) args of
56 (_,_,errs) | not (null errs)
57 -> do putStrLn "hpc failed:"
58 sequence [ putStr (" " ++ err)
65 let flags = foldr (.) (final_flags plugin) o
67 implementation plugin flags ns
72 ------------------------------------------------------------------------------
83 hooks' = [ (name hook,hook) | hook <- hooks ]
85 ------------------------------------------------------------------------------
87 help_plugin = Plugin { name = "help"
88 , usage = "[<HPC_COMMAND>]"
89 , summary = "Display help for hpc or a single command."
90 , options = help_options
91 , implementation = help_main
92 , init_flags = default_flags
93 , final_flags = default_final_flags
96 help_main flags [] = do
99 help_main flags (sub_txt:_) = do
100 case lookup sub_txt hooks' of
102 putStrLn $ "no such hpc command : " ++ sub_txt
105 command_usage plugin'
110 ------------------------------------------------------------------------------
112 version_plugin = Plugin { name = "version"
114 , summary = "Display version for hpc"
116 , implementation = version_main
117 , init_flags = default_flags
118 , final_flags = default_final_flags
121 version_main _ _ = putStrLn $ "hpc tools, version 0.5-dev"
124 ------------------------------------------------------------------------------