1{-# LANGUAGE DeriveDataTypeable, RecordWildCards, TemplateHaskell, MagicHash #-}
2{-# OPTIONS_GHC -fno-warn-missing-fields #-}
3module System.Console.CmdArgs.Test.Implicit.Diffy where
4import System.Console.CmdArgs
5import System.Console.CmdArgs.Quote
6import System.Console.CmdArgs.Test.Implicit.Util
7
8data Diffy = Create {src :: Maybe FilePath, out :: FilePath}
9           | Diff {old :: FilePath, new :: FilePath, out :: FilePath}
10             deriving (Data,Typeable,Show,Eq)
11
12outFlags x = x &= help "Output file" &= typFile
13
14create = Create
15    {src = def &= help "Source directory" &= typDir
16    ,out = outFlags "ls.txt"
17    } &= help "Create a fingerprint"
18
19diff = Diff
20    {old = def &= typ "OLDFILE" &= argPos 0
21    ,new = def &= typ "NEWFILE" &= argPos 1
22    ,out = outFlags "diff.txt"
23    } &= help "Perform a diff"
24
25mode = cmdArgsMode $ modes [create,diff] &= help "Create and compare differences" &= program "diffy" &= summary "Diffy v1.0"
26
27
28$(cmdArgsQuote
29    [d|
30        outFlags_ x = x &=# help "Output file" &=# typFile
31
32        create_ = Create
33            {src = Nothing &=# help "Source directory" &=# typDir
34            ,out = outFlags_ "ls.txt"
35            } &=# help "Create a fingerprint"
36
37        diff_ = Diff
38            {old = "" &=# typ "OLDFILE" &=# argPos 0
39            ,new = "" &=# typ "NEWFILE" &=# argPos 1
40            ,out = outFlags_ "diff.txt"
41            } &=# help "Perform a diff"
42
43        mode_ = cmdArgsMode# $ modes# [create_,diff_] &=# help "Create and compare differences" &=# program "diffy" &=# summary "Diffy v1.0"
44    |])
45
46
47-- STOP MANUAL
48
49test = do
50    let Tester{..} = testers "Diffy" [mode,mode_]
51    fails []
52    isHelp ["--help"] ["diffy [COMMAND] ... [OPTIONS]"] -- FIXME: Should know that root is not valid, thus no brackets on [COMMAND]
53    isHelp ["create","--help"] []
54    isHelp ["diff","--help"] []
55    isHelpNot ["--help"] ["diffy"]
56    isVersion ["--version"] "Diffy v1.0"
57    isVersion ["--numeric-version"] "1.0"
58    ["create"] === create
59    fails ["create","file1"]
60    fails ["create","--quiet"]
61    fails ["create","--verbose"]
62    isVerbosity ["create"] Normal
63    ["create","--src","x"] === create{src=Just "x"}
64    ["create","--src","x","--src","y"] === create{src=Just "y"}
65    fails ["diff","--src","x"]
66    fails ["create","foo"]
67    ["diff","foo1","foo2"] === diff{old="foo1",new="foo2"}
68    fails ["diff","foo1"]
69    fails ["diff","foo1","foo2","foo3"]
70    completion [] (0,0) [CompleteValue "create",CompleteValue "diff",CompleteValue "--out",CompleteValue "--help",CompleteValue "--version",CompleteValue "--numeric-version"]
71    completion ["d"] (0,1) [CompleteValue "diff"]
72    completion ["dd"] (0,2) []
73
74