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