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 = ["combine"]
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 ------------------------------------------------------------------------------
87 hooks' = [ (name hook,hook) | hook <- hooks ]
89 ------------------------------------------------------------------------------
91 help_plugin = Plugin { name = "help"
92 , usage = "[<HPC_COMMAND>]"
93 , summary = "Display help for hpc or a single command."
94 , options = help_options
95 , implementation = help_main
96 , init_flags = default_flags
97 , final_flags = default_final_flags
100 help_main flags [] = do
103 help_main flags (sub_txt:_) = do
104 case lookup sub_txt hooks' of
106 putStrLn $ "no such hpc command : " ++ sub_txt
109 command_usage plugin'
114 ------------------------------------------------------------------------------
116 version_plugin = Plugin { name = "version"
118 , summary = "Display version for hpc"
120 , implementation = version_main
121 , init_flags = default_flags
122 , final_flags = default_final_flags
125 version_main _ _ = putStrLn $ "hpc tools, version 0.5-dev"
128 ------------------------------------------------------------------------------