1 % Copyright (C) 2002-2004 David Roundy
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)
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; see the file COPYING. If not, write to
15 % the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 % Boston, MA 02110-1301, USA.
18 \subsection{darcs help}
21 You could also call \verb|help| as a command. This is equivalent to calling
23 the \verb|--help| to that command. For example, \verb|darcs help query manifest|
24 is equivalent to \verb|darcs query manifest --help|.
27 module Darcs.Commands.Help ( help_cmd, command_control_list, print_version,
28 list_available_commands
30 import System.Exit ( ExitCode(..), exitWith )
32 import Autoconf( darcs_version )
33 import Darcs.Commands ( CommandControl(Command_data), DarcsCommand(..),
34 disambiguate_commands, CommandArgs(..),
35 get_command_help, extract_commands,
38 import Darcs.Arguments ( DarcsFlag(..), help_on_match )
39 import Darcs.External ( viewDoc )
40 import Darcs.Patch.Match ( helpOnMatchers )
41 import Darcs.Utils ( withCurrentDirectory )
42 import Printer ( text )
43 import Workaround ( getCurrentDirectory )
44 import qualified Darcs.TheCommands as TheCommands
49 \haskell{help_description}
51 help_description :: String
52 help_description = "Display help for darcs or a single command."
59 "help displays usage information for darcs in general or for a single\n" ++
60 "command (for example, darcs help query manifest).\n\n"
65 help = DarcsCommand {command_name = "help",
66 command_help = help_help,
67 command_description = help_description,
68 command_extra_args = -1,
69 command_extra_arg_help = ["[<DARCS_COMMAND> [DARCS_SUBCOMMAND]] "],
70 command_command = help_cmd,
71 command_prereq = \_ -> return $ Right (),
72 command_get_arg_possibilities = return [],
73 command_argdefaults = nodefaults,
74 command_advanced_options = [],
75 command_basic_options = [help_on_match]}
79 help_cmd :: [DarcsFlag] -> [String] -> IO ()
82 case () of _ | HelpOnMatch `elem` opts -> helpOnMatchers
83 | otherwise -> usage command_control_list
84 exitWith $ ExitSuccess
86 help_cmd _ (cmd:args) =
87 do let disambiguated = disambiguate_commands command_control_list cmd args
91 let msg = case cmds of
92 CommandOnly c -> get_command_help Nothing c
93 SuperCommandOnly c -> get_command_help Nothing c
94 SuperCommandSub c s -> get_command_help (Just c) s
96 exitWith $ ExitSuccess
98 list_available_commands :: IO ()
99 list_available_commands =
100 do here <- getCurrentDirectory
101 is_valid <- sequence $ map
102 (\c-> withCurrentDirectory here $ (command_prereq c) [])
103 (extract_commands command_control_list)
104 putStr $ unlines $ map (command_name . fst) $
105 filter (isRight.snd) $
106 zip (extract_commands command_control_list) is_valid
109 putStrLn "--exact-version"
110 putStrLn "--overview"
111 where isRight (Right _) = True
116 print_version :: IO ()
117 print_version = putStrLn $ "darcs version " ++ darcs_version
121 -- avoiding a module import cycle between Help and TheCommands
122 command_control_list :: [CommandControl]
123 command_control_list =
124 Command_data help : TheCommands.command_control_list