Sun Dec 18 18:25:58 CET 2005 Eric Kow <[EMAIL PROTECTED]>
* Implementation of help command
(RT #307)
Provides a command to display usage information on the screen.
darcs help = darcs --help
darcs help --verbose = darcs --extended-help
darcs help command = darcs command --help
This implementation understands abbreviated commands and subcommands.
Slightly refactors darcs.lhs.
New patches:
[Implementation of help command
Eric Kow <[EMAIL PROTECTED]>**20051218172558
(RT #307)
Provides a command to display usage information on the screen.
darcs help = darcs --help
darcs help --verbose = darcs --extended-help
darcs help command = darcs command --help
This implementation understands abbreviated commands and subcommands.
Slightly refactors darcs.lhs.
] {
hunk ./DarcsCommands.lhs 28
+ disambiguate_commands,
+ get_command_help,
hunk ./DarcsCommands.lhs 368
- unwords (command_extra_arg_help cmd) ++
+ unwords args_help ++
hunk ./DarcsCommands.lhs 372
- where super_name = case msuper of
+ where args_help =
+ case cmd of
+ (DarcsCommand _ _ _ _ _ _ _ _ _ _) ->
+ command_extra_arg_help cmd
+ _ -> []
+ super_name = case msuper of
hunk ./DarcsCommands.lhs 401
+\end{code}
+
+\begin{code}
+-- parses a darcs command line with potentially abbreviated commands
+-- If it fails, returns Left (error message)
+-- If it suceeds, returns Right (cmds, args)
+-- where cmds is a disambiguated list [command, subcommand, sub-subcommand, ..]
+-- and args are the arguments to the commands
+--
+-- Fails if it there is a command that it cannot disambiguate
+-- note that currently in darcs, there are only two layers, command and sub-command
+disambiguate_commands :: [CommandControl] -> [String] -> Either String ([DarcsCommand], [String])
+disambiguate_commands _ [] = Right ([],[])
+disambiguate_commands cs (cmd:args) =
+ case filter ((==cmd).take (length cmd).command_name) (extract_commands cs) of
+ [] -> Left $ "No such command '" ++ cmd ++ "'\n"
+ [c] -> let possibleSub = get_subcommands c
+ in if null possibleSub
+ then Right ([c], args)
+ else let next = disambiguate_commands possibleSub args
+ in case next of
+ Right (c', args') -> Right (c:c', args')
+ err -> err
+ cs' -> Left $ "Ambiguous command...\n\n" ++
+ "The command '"++cmd++"' could mean one of:\n" ++
+ unwords (sort $ map command_name cs')
hunk ./GNUmakefile 45
- Email.hs Get.lhs Init.lhs Mv.lhs Optimize.lhs Pull.lhs Push.lhs \
- Put.lhs Query.lhs QueryManifest.lhs Record.lhs RemoteApply.lhs \
+ Email.hs Get.lhs Help.lhs Init.lhs Mv.lhs Optimize.lhs \
+ Pull.lhs Push.lhs Put.lhs \
+ Query.lhs QueryManifest.lhs Record.lhs RemoteApply.lhs \
addfile ./Help.lhs
hunk ./Help.lhs 1
+% Copyright (C) 2002-2004 David Roundy
+%
+% This program is free software; you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation; either version 2, or (at your option)
+% any later version.
+%
+% This program is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License for more details.
+%
+% You should have received a copy of the GNU General Public License
+% along with this program; if not, write to the Free Software Foundation,
+% Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+\subsection{darcs help}
+\label{help}
+
+You could also call \verb|help| as a command. This is equivalent to calling
+darcs --help.
+The \verb|--verbose| argument is equivalent to the darcs option
+\verb|--extended-help|
+If you pass it another command as an argument, it will be equivalent to passing
+the \verb|--help| to that command. For example, \verb|darcs help query manifest|
+is equivalent to \verb|darcs query manifest --help|.
+
+\begin{code}
+module Help ( help, command_control_list, print_version ) where
+import System ( ExitCode(..), exitWith )
+
+import Autoconf( darcs_version )
+import DarcsCommands ( CommandControl(Command_data), DarcsCommand(..),
+ disambiguate_commands,
+ extended_usage, get_command_help,
+ nodefaults,
+ usage )
+import DarcsArguments ( DarcsFlag(..),
+ verbose,
+ )
+import DarcsUtils ( bug )
+import qualified TheCommands
+import Debug.Trace
+\end{code}
+
+\options{help}
+
+\haskell{help_description}
+\begin{code}
+help_description :: String
+help_description = "Display help for darcs or a single commands."
+\end{code}
+\haskell{help_help}
+
+\begin{code}
+help_help :: String
+help_help =
+ "help displays usage information for darcs in general or for a single\n" ++
+ "command (for example, darcs help query manifest).\n" ++
+ "Note that --verbose prints extra help for darcs as a whole\n" ++
+ ", but it makes no difference for a single command."
+\end{code}
+
+\begin{code}
+help :: DarcsCommand
+help = DarcsCommand {command_name = "help",
+ command_help = help_help,
+ command_description = help_description,
+ command_extra_args = -1,
+ command_extra_arg_help = ["[<DARCS_COMMAND> [DARCS_SUBCOMMAND]] "],
+ command_command = help_cmd,
+ command_prereq = \_ -> return $ Right "",
+ command_get_arg_possibilities = return [],
+ command_argdefaults = nodefaults,
+ command_darcsoptions = [verbose]}
+\end{code}
+
+\begin{code}
+help_cmd :: [DarcsFlag] -> [String] -> IO ()
+help_cmd opts [] =
+ do print_version
+ putStr $ if Verbose `elem` opts
+ then extended_usage
+ else usage command_control_list
+ exitWith $ ExitSuccess
+
+help_cmd _ args =
+ do print_version
+ let disambiguated = disambiguate_commands command_control_list args
+ case disambiguated of
+ Left err -> fail err
+ Right (cmds,_) ->
+ case cmds of
+ [] -> error $ disambBug "null commands"
+ [c] -> putStr $ trace ("only command: " ++ show args) $ get_command_help Nothing c
+ [c,s] -> putStr $ get_command_help (Just c) s
+ _ -> error $ disambBug "subsubcommands"
+ exitWith $ ExitSuccess
+ where disambBug m = bug $ "help_cmd case uncaught by disambiguateCmds: " ++ m
+\end{code}
+
+\begin{code}
+print_version :: IO ()
+print_version = putStrLn $ "darcs version" ++ darcs_version
+\end{code}
+
+\begin{code}
+-- avoiding a module import cycle between Help and TheCommands
+command_control_list :: [CommandControl]
+command_control_list =
+ Command_data help : TheCommands.command_control_list
+\end{code}
+
hunk ./darcs.lhs 37
-import DarcsCommands ( command_name, command_prereq, extract_commands,
- run_the_command, usage, extended_usage, )
-import TheCommands ( command_control_list, )
+import DarcsCommands ( command_command, command_name, command_prereq, extract_commands,
+ run_the_command, usage )
+import DarcsFlags ( DarcsFlag(Verbose) )
+import Help ( command_control_list, help, print_version )
hunk ./darcs.lhs 668
- do putStrLn $ "darcs version "++darcs_version
+ do print_version
hunk ./darcs.lhs 682
- do putStrLn $ "darcs version "++darcs_version
- putStr $ usage command_control_list
- exitWith $ ExitSuccess
+ command_command help [] []
hunk ./darcs.lhs 684
- do putStrLn $ "darcs version "++darcs_version
- putStr $ extended_usage
- exitWith $ ExitSuccess
+ command_command help [Verbose] []
hunk ./darcs.lhs 730
+
+\section{Getting help}
+
+\input{Help.lhs}
hunk ./preproc.hs 6
-import TheCommands ( command_control_list )
+import Help ( command_control_list )
}
Context:
[properly quote paths so that paths with spaces in them are okay
[EMAIL PROTECTED]
[fix up debug printouts in cygwin-wrapper.bash
[EMAIL PROTECTED]
[smoother invocation of cygwin-wrapper.bash -- it detects fully-qualified path to itself by leading /
[EMAIL PROTECTED]
[modernize amend-record.pl to be more portable.
Mark Stosberg <[EMAIL PROTECTED]>**20050402133417
This depends on the new "echo_to_darcs()" function in Test::Darcs
]
[implementation of --set-scripts-executable on local darcs get
[EMAIL PROTECTED]
proposed fix for issue38
The --set-scripts-executable flag is normally evaluated when you apply
patches. But when you do a local darcs get, no patches are applied.
So as a solution, we traverse the directory on local darcs get , and set
any script files to be executable.
Note: one flaw in this patch is that it duplicates the definition of
what a script is -- a file that starts with #! -- in PatchApply.lhs and
Get.lhs. It might be good to refactor these somehow.
]
[extended set-scripts-executable test
[EMAIL PROTECTED]
added check for local darcs get (issue 38) as well as initial sanity check
]
[Fix merge conflicts.
Juliusz Chroboczek <[EMAIL PROTECTED]>**20051214223217]
[Add --subject flag to 'darcs send'
Joeri van Ruth <[EMAIL PROTECTED]>**20051205120301]
[print out the patch name when a test fails.
Zachary P. Landau <[EMAIL PROTECTED]>**20051205055109]
[revert maybe_relink and atomic_create to original C code.
David Roundy <[EMAIL PROTECTED]>**20051208131213]
[resolve conflicts between stable and unstable.
David Roundy <[EMAIL PROTECTED]>**20051206134818]
[Merge changes
Ian Lynagh <[EMAIL PROTECTED]>**20051008225210]
[fix mkstemp implementation for win32
Peter Strand <[EMAIL PROTECTED]>**20050810211303]
[Implement parts of System.Posix.(IO|Files) for win32
[EMAIL PROTECTED]
[implement RawMode with library functions instead of ffi
[EMAIL PROTECTED]
[call hsc2hs without output filename argument
[EMAIL PROTECTED]
[Rename compat.c to c_compat.c to avoid object filename conflict with Compat.hs
[EMAIL PROTECTED]
[Move atomic_create/sloppy_atomic_create to Compat
Ian Lynagh <[EMAIL PROTECTED]>**20050730141703]
[Split the raw mode stuff out into its own .hsc file. Windows needs some TLC
Ian Lynagh <[EMAIL PROTECTED]>**20050730134030]
[Move maybe_relink out of compat.c
Ian Lynagh <[EMAIL PROTECTED]>**20050730131205]
[Remove is_symlink
Ian Lynagh <[EMAIL PROTECTED]>**20050730122255]
[Move mkstemp to Compat.hs
Ian Lynagh <[EMAIL PROTECTED]>**20050730020918]
[Start Compat.hs, and move stdout_is_a_pipe from compat.c
Ian Lynagh <[EMAIL PROTECTED]>**20050730004829]
[Fix mistyped /dev/null, fixes --sendmail-command in Windows
Esa Ilari Vuokko <[EMAIL PROTECTED]>**20051129160120]
[Use \ as path separator for GnuPG in Windows -- makes apply --verify work
Esa Ilari Vuokko <[EMAIL PROTECTED]>**20051129164533]
[make dangers and recommended use of "Amend" clearer in the docs.
Mark Stosberg <[EMAIL PROTECTED]>**20051213140523
I think it's important to be clearer about when it's appropriate to use 'amend',
so I moved some notes into the short and mid-length help texts.
]
[update web page to reflect 1.0.5 as latest stable source.
Tommy Pettersson <[EMAIL PROTECTED]>**20051213111137]
[fix handling of absolute paths containing drive letters
Will <[EMAIL PROTECTED]>**20051208054737
This fixes issue 47 where paths containing drive letters (i.e. on windows)
are not treated as absolute paths.
]
[bump version to 1.0.6pre1
Tommy Pettersson <[EMAIL PROTECTED]>**20051208092839]
[TAG 1.0.5
Tommy Pettersson <[EMAIL PROTECTED]>**20051207112730]
Patch bundle hash:
4a739273b3320eb8a676e9b34c0a6068a95e6f4d
_______________________________________________
darcs-devel mailing list
[email protected]
http://www.abridgegame.org/cgi-bin/mailman/listinfo/darcs-devel