Follow upstream changes -- Bytestring updates
[git-darcs-import.git] / src / darcsman.hs
bloba1512209d295183eb9b0894ac14e93216162d4c4
1 -- Copyright (C) 2003 David Roundy
2 --
3 -- This program is free software; you can redistribute it and/or modify
4 -- it under the terms of the GNU General Public License as published by
5 -- the Free Software Foundation; either version 2, or (at your option)
6 -- any later version.
7 --
8 -- This program is distributed in the hope that it will be useful,
9 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
10 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 -- GNU General Public License for more details.
13 -- You should have received a copy of the GNU General Public License
14 -- along with this program; if not, write to the Free Software Foundation,
15 -- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 module Main (main) where
19 import Darcs.Commands
20 import Darcs.TheCommands
21 import Time
23 main :: IO ()
24 main = man (extract_commands command_control_list)
26 man :: [DarcsCommand] -> IO ()
27 man cs = do man_header
28 unorganized <- man_organizer cs
29 putStrLn ".SH OTHER COMMANDS"
30 man_helper unorganized
31 man_trailer
33 man_organizer :: [DarcsCommand] -> IO [DarcsCommand]
34 man_organizer commands = mo commands
35 [("CREATING REPOSITORIES",
36 ["initialize","get"]),
37 ("MODIFYING REPOSITORY CONTENTS",
38 ["add","remove","mv","replace"]),
39 ("WORKING WITH CHANGES",
40 ["record","pull","push","send","apply"]),
41 ("SEEING WHAT YOU'VE DONE",
42 ["whatsnew","query"])
44 where mo :: [DarcsCommand] -> [(String,[String])] -> IO [DarcsCommand]
45 mo cs [] = return cs
46 mo cs ((t,a):xs) =
47 do putStrLn $ ".SH " ++ t
48 man_helper $ filter ((`elem` a) . command_name) cs
49 mo (filter (not . (`elem` a) . command_name) cs) xs
51 man_helper :: [DarcsCommand] -> IO ()
52 man_helper cmds =
53 helper' "" cmds
54 where helper' _ [] = return ()
55 helper' s (c@DarcsCommand { }:cs) = do
56 putStrLn $ ".TP"
57 putStrLn $ ".B "++ s ++ " " ++ command_name c
58 putStrLn $ command_help c
59 helper' s cs
60 helper' s (c@SuperCommand { }:cs) = do
61 helper' (command_name c ++ " " ++ s)
62 (extract_commands (command_sub_commands c))
63 helper' s cs
65 man_trailer :: IO ()
66 man_trailer = do putStrLn ""
67 putStrLn ".SH BUGS"
68 putStrLn "Report bugs by mail to"
69 putStrLn ".B bugs@darcs.net"
70 putStrLn "or via the web site at"
71 putStrLn ".BR http://bugs.darcs.net/ ."
72 putStrLn ""
73 putStrLn ".SH AUTHOR"
74 putStrLn "David Roundy <droundy@abridgegame.org>."
76 man_header :: IO ()
77 man_header = do
78 putStr ".TH DARCS \"1\" \""
79 cl <- getClockTime
80 ct <- toCalendarTime cl
81 putStr $ show (ctMonth ct) ++ " " ++ show (ctYear ct)
82 putStr "\" \"darcs\" \"User Commands\"\n"
83 putStr $
84 ".SH NAME\n"++
85 "darcs \\- an advanced revision control system\n"++
86 ".SH SYNOPSIS\n"++
87 ".B darcs\n"++
88 "\\fICOMMAND \\fR...\n"++
89 ".SH DESCRIPTION\n"++
90 "\n"++
91 "darcs is a nifty revision control tool. For more a detailed description,\n"++
92 "see the html documentation, which should be available at\n"++
93 "/usr/share/doc/darcs/manual/index.html. To easily get more specific help\n"++
94 "on each command, you can call `darcs COMMAND --help'.\n"++
95 "\n"