| darcs-2.4.3: a distributed, interactive, smart revision control system | Source code | Contents | Index
CommandLine
Description
A parser for commandlines, returns an arg list and expands format strings given in a translation table. Additionally the commandline can end with %< specifying that the command expects input on stdin. Some tests for the parser.
     formatTable = [('s',"<insert subject here>"),
                    ('a',"<insert author here>")]

     testParser :: (Show a, Eq a) => Parser a -> String -> a -> a
     testParser p s ok = case parse p "" s of
                         Left e -> error $ "Parser failed with: " ++ (show e)
                         Right res -> if res == ok
                                      then res
                                      else error $ "Parser failed: got "
                                             ++ (show res) ++ ", expected "
                                             ++ (show ok)

     testCases = [("a b",(["a","b"], False)),
                  ("a b %<",(["a","b"], True)),
                  ("a b %< ",(["a","b"], True)),
                  ("\"arg0 contains spaces \\\"quotes\\\"\" b",
                   (["arg0 contains spaces \"quotes\"","b"],False)),
                  ("a %s %<",(["a","<insert subject here>"], True))]

     runTests = map (uncurry $ testParser (commandline formatTable)) testCases
Synopsis
parseCmd :: FTable -> String -> Either ParseError ([String], Bool)
addUrlencoded :: FTable -> FTable
Documentation
parseCmd :: FTable -> String -> Either ParseError ([String], Bool) | Source
parse a commandline returning a list of strings (intended to be used as argv) and a bool value which specifies if the command expects input on stdin format specifiers with a mapping in ftable are accepted and replaced by the given strings. E.g. if the ftable is [(s,Some subject)], then %s is replaced by Some subject
addUrlencoded :: FTable -> FTable | Source
for every mapping (c,s), add a mapping with uppercase c and the urlencoded string s
Produced by Haddock version 2.4.2