1{-# LANGUAGE GADTs #-} 2module Terminal.Internal 3 ( Command(..) 4 , toName 5 , Summary(..) 6 , Flags(..) 7 , Flag(..) 8 , Parser(..) 9 , Args(..) 10 , CompleteArgs(..) 11 , RequiredArgs(..) 12 ) 13 where 14 15 16import Text.PrettyPrint.ANSI.Leijen (Doc) 17 18 19 20-- COMMAND 21 22 23data Command where 24 Command 25 :: String 26 -> Summary 27 -> String 28 -> Doc 29 -> Args args 30 -> Flags flags 31 -> (args -> flags -> IO ()) 32 -> Command 33 34 35toName :: Command -> String 36toName (Command name _ _ _ _ _ _) = 37 name 38 39 40 41{-| The information that shows when you run the executable with no arguments. 42If you say it is `Common`, you need to tell people what it does. Try to keep 43it to two or three lines. If you say it is `Uncommon` you can rely on `Details` 44for a more complete explanation. 45-} 46data Summary = Common String | Uncommon 47 48 49 50-- FLAGS 51 52 53data Flags a where 54 FDone :: a -> Flags a 55 FMore :: Flags (a -> b) -> Flag a -> Flags b 56 57 58data Flag a where 59 Flag :: String -> Parser a -> String -> Flag (Maybe a) 60 OnOff :: String -> String -> Flag Bool 61 62 63 64-- PARSERS 65 66 67data Parser a = 68 Parser 69 { _singular :: String 70 , _plural :: String 71 , _parser :: String -> Maybe a 72 , _suggest :: String -> IO [String] 73 , _examples :: String -> IO [String] 74 } 75 76 77 78-- ARGS 79 80 81newtype Args a = 82 Args [CompleteArgs a] 83 84 85data CompleteArgs args where 86 Exactly :: RequiredArgs args -> CompleteArgs args 87 Multiple :: RequiredArgs ([a] -> args) -> Parser a -> CompleteArgs args 88 Optional :: RequiredArgs (Maybe a -> args) -> Parser a -> CompleteArgs args 89 90 91data RequiredArgs a where 92 Done :: a -> RequiredArgs a 93 Required :: RequiredArgs (a -> b) -> Parser a -> RequiredArgs b 94