Copyright | (c) Justin Le 2019 |
---|---|
License | BSD3 |
Maintainer | justin@jle.im |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Internal module providing a data structure for representing structure of
command line parsers that can be manipulated as an ADT, as well as
functionality to interpret it as a Parser
command line argument
parser.
Synopsis
- data OptRead :: Type -> Type where
- ORRequired :: ReadM a -> OptRead a
- OROptional :: ReadM a -> OptRead (Maybe a)
- ORSwitch :: OptRead Bool
- data Opt a = Opt {}
- data Arg a = Arg {}
- data MultiArg :: Type -> Type where
- type Captures = Day Arg PStruct :+: Day MultiArg EndpointMap
- newtype Endpoint a = Endpoint {}
- data EndpointMap a = EPM {}
- data PStruct a = PStruct {
- psInfo :: [String]
- psComponents :: Map String (PStruct a)
- psCaptures :: Maybe (Captures a)
- psEndpoints :: EndpointMap a
- data PStructF (a :: Type) r = PStructF {
- psInfoF :: [[Char]]
- psComponentsF :: (Map [Char] r)
- psCapturesF :: (Maybe ((:+:) (Day Arg PStruct) (Day MultiArg EndpointMap) a))
- psEndpointsF :: (EndpointMap a)
- structParser :: PStruct a -> InfoMod a -> ParserInfo a
- structParser_ :: PStruct a -> Bool -> [String] -> InfoMod a -> ParserInfo a
- branch :: PStruct a -> PStruct b -> PStruct (Either a b)
- ($:>) :: String -> PStruct a -> PStruct a
- (%:>) :: Parser a -> PStruct (a -> b) -> PStruct b
- (?:>) :: Opt a -> PStruct (a -> b) -> PStruct b
- (#:>) :: Arg a -> PStruct (a -> b) -> PStruct b
- (##:>) :: Arg a -> PStruct ([a] -> b) -> PStruct b
- note :: [String] -> PStruct a -> PStruct a
- endpoint :: Method -> a -> PStruct a
- rawEndpoint :: (Method -> a) -> PStruct a
- orRequired :: ReadM a -> Coyoneda OptRead a
- orOptional :: ReadM a -> Coyoneda OptRead (Maybe a)
- orSwitch :: Coyoneda OptRead Bool
Documentation
data OptRead :: Type -> Type where Source #
How to "read" an option.
ORRequired :: ReadM a -> OptRead a | |
OROptional :: ReadM a -> OptRead (Maybe a) | |
ORSwitch :: OptRead Bool |
Query parameters are interpreted as options
Captures are interpreted as arguments
data MultiArg :: Type -> Type where Source #
Interpret an Arg
as something that can be given repeatedly an
arbitrary number of times.
type Captures = Day Arg PStruct :+: Day MultiArg EndpointMap Source #
Captures can be a single capture leading to the next level, or a multi-capture leading to an endpoint action.
Endpoint arguments and body.
data EndpointMap a Source #
A map of endpoints associated with methods, paired with an optional "raw" endpoint.
Instances
Functor EndpointMap Source # | |
Defined in Servant.CLI.Internal.PStruct fmap :: (a -> b) -> EndpointMap a -> EndpointMap b # (<$) :: a -> EndpointMap b -> EndpointMap a # | |
Semigroup (EndpointMap a) Source # | Combine two |
Defined in Servant.CLI.Internal.PStruct (<>) :: EndpointMap a -> EndpointMap a -> EndpointMap a # sconcat :: NonEmpty (EndpointMap a) -> EndpointMap a # stimes :: Integral b => b -> EndpointMap a -> EndpointMap a # | |
Monoid (EndpointMap a) Source # | |
Defined in Servant.CLI.Internal.PStruct mempty :: EndpointMap a # mappend :: EndpointMap a -> EndpointMap a -> EndpointMap a # mconcat :: [EndpointMap a] -> EndpointMap a # |
Structure for a parser of a given value that may use items from captures and arguments.
PStruct | |
|
Instances
Functor PStruct Source # | |
Semigroup (PStruct a) Source # | Combine two |
Monoid (PStruct a) Source # | |
Recursive (PStruct a) Source # | |
Defined in Servant.CLI.Internal.PStruct project :: PStruct a -> Base (PStruct a) (PStruct a) # cata :: (Base (PStruct a) a0 -> a0) -> PStruct a -> a0 # para :: (Base (PStruct a) (PStruct a, a0) -> a0) -> PStruct a -> a0 # gpara :: (Corecursive (PStruct a), Comonad w) => (forall b. Base (PStruct a) (w b) -> w (Base (PStruct a) b)) -> (Base (PStruct a) (EnvT (PStruct a) w a0) -> a0) -> PStruct a -> a0 # prepro :: Corecursive (PStruct a) => (forall b. Base (PStruct a) b -> Base (PStruct a) b) -> (Base (PStruct a) a0 -> a0) -> PStruct a -> a0 # gprepro :: (Corecursive (PStruct a), Comonad w) => (forall b. Base (PStruct a) (w b) -> w (Base (PStruct a) b)) -> (forall c. Base (PStruct a) c -> Base (PStruct a) c) -> (Base (PStruct a) (w a0) -> a0) -> PStruct a -> a0 # | |
Corecursive (PStruct a) Source # | |
Defined in Servant.CLI.Internal.PStruct embed :: Base (PStruct a) (PStruct a) -> PStruct a # ana :: (a0 -> Base (PStruct a) a0) -> a0 -> PStruct a # apo :: (a0 -> Base (PStruct a) (Either (PStruct a) a0)) -> a0 -> PStruct a # postpro :: Recursive (PStruct a) => (forall b. Base (PStruct a) b -> Base (PStruct a) b) -> (a0 -> Base (PStruct a) a0) -> a0 -> PStruct a # gpostpro :: (Recursive (PStruct a), Monad m) => (forall b. m (Base (PStruct a) b) -> Base (PStruct a) (m b)) -> (forall c. Base (PStruct a) c -> Base (PStruct a) c) -> (a0 -> Base (PStruct a) (m a0)) -> a0 -> PStruct a # | |
type Base (PStruct a) Source # | |
Defined in Servant.CLI.Internal.PStruct |
data PStructF (a :: Type) r Source #
PStructF | |
|
Instances
Functor (PStructF a) Source # | |
Foldable (PStructF a) Source # | |
Defined in Servant.CLI.Internal.PStruct fold :: Monoid m => PStructF a m -> m # foldMap :: Monoid m => (a0 -> m) -> PStructF a a0 -> m # foldr :: (a0 -> b -> b) -> b -> PStructF a a0 -> b # foldr' :: (a0 -> b -> b) -> b -> PStructF a a0 -> b # foldl :: (b -> a0 -> b) -> b -> PStructF a a0 -> b # foldl' :: (b -> a0 -> b) -> b -> PStructF a a0 -> b # foldr1 :: (a0 -> a0 -> a0) -> PStructF a a0 -> a0 # foldl1 :: (a0 -> a0 -> a0) -> PStructF a a0 -> a0 # toList :: PStructF a a0 -> [a0] # null :: PStructF a a0 -> Bool # length :: PStructF a a0 -> Int # elem :: Eq a0 => a0 -> PStructF a a0 -> Bool # maximum :: Ord a0 => PStructF a a0 -> a0 # minimum :: Ord a0 => PStructF a a0 -> a0 # | |
Traversable (PStructF a) Source # | |
Defined in Servant.CLI.Internal.PStruct |
:: PStruct a | The |
-> InfoMod a | Modify how the top-level prompt is displayed. |
-> ParserInfo a |
Convert a PStruct
into a command line argument parser, from the
optparse-applicative library. It can be run with execParser
.
It takes options on how the top-level prompt is displayed when given
"--help"
; it can be useful for adding a header or program description.
Otherwise, just use mempty
.
:: PStruct a | |
-> Bool | add helper |
-> [String] | root path |
-> InfoMod a | modify top level |
-> ParserInfo a |
Low-level implementation of structParser
.
Creating
branch :: PStruct a -> PStruct b -> PStruct (Either a b) infixr 3 Source #
Combine two PStruct
s in an either-or fashion, favoring the left hand
side.
(%:>) :: Parser a -> PStruct (a -> b) -> PStruct b infixr 4 Source #
Add a request body to all endpoints.
If done more than once per endpoint, it runs *both* parsers; however, we can only send one request body, so this is undefined behavior as a client.
(?:>) :: Opt a -> PStruct (a -> b) -> PStruct b infixr 4 Source #
Add a command-line option to all endpoints.
(##:>) :: Arg a -> PStruct ([a] -> b) -> PStruct b infixr 4 Source #
Add a repeating argument parser.
note :: [String] -> PStruct a -> PStruct a infixr 4 Source #
Add notes to the beginning of a documentation level.
rawEndpoint :: (Method -> a) -> PStruct a Source #
Create a raw endpoint.