Copyright | (c) Justin Le 2019 |
---|---|
License | BSD3 |
Maintainer | [email protected] |
Stability | experimental |
Portability | non-portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Servant.CLI
Description
Parse command line arguments into a servant client, from a servant API.
Mainly used through parseClient
and parseHandleClient
.
parseClient
returns a servant client action that returns nested
Either
s for every endpoint, but parseHandleClient
allows you to
conveniently specify how you want to sort each endpoint entry into
a single result.
See README for a tutorial.
Synopsis
- parseClient :: HasCLI m api '[] => Proxy api -> Proxy m -> InfoMod (m (CLIResult m api)) -> IO (m (CLIResult m api))
- parseHandleClient :: (HasCLI m api '[], Functor m) => Proxy api -> Proxy m -> InfoMod (m (CLIResult m api)) -> CLIHandler m api r -> IO (m r)
- parseClientWithContext :: HasCLI m api context => Proxy api -> Proxy m -> Rec (ContextFor m) context -> InfoMod (m (CLIResult m api)) -> IO (m (CLIResult m api))
- parseHandleClientWithContext :: forall m api context r. (HasCLI m api context, Functor m) => Proxy api -> Proxy m -> Rec (ContextFor m) context -> InfoMod (m (CLIResult m api)) -> CLIHandler m api r -> IO (m r)
- class HasCLI m api ctx where
- data family ContextFor (m :: Type -> Type) :: Type -> Type
- newtype NamedContext m (name :: Symbol) (subContext :: [Type]) = NamedContext (Rec (ContextFor m) subContext)
- descendIntoNamedContext :: forall (name :: Symbol) context subContext m. NamedContext m name subContext ∈ context => Proxy name -> Rec (ContextFor m) context -> Rec (ContextFor m) subContext
- cliPStruct :: HasCLI m api '[] => Proxy m -> Proxy api -> PStruct (m (CLIResult m api))
- cliPStructWithContext :: HasCLI m api context => Proxy m -> Proxy api -> Rec (ContextFor m) context -> PStruct (m (CLIResult m api))
- structParser :: PStruct a -> InfoMod a -> ParserInfo a
- cliHandlePStruct :: (HasCLI m api '[], Functor m) => Proxy m -> Proxy api -> CLIHandler m api r -> PStruct (m r)
- cliHandlePStructWithContext :: forall m api context r. (HasCLI m api context, Functor m) => Proxy m -> Proxy api -> Rec (ContextFor m) context -> CLIHandler m api r -> PStruct (m r)
- class ParseBody a where
- defaultParseBody :: String -> ReadM a -> Parser a
- class ToCapture (c :: k) where
- toCapture :: Proxy c -> DocCapture
- data DocCapture = DocCapture {
- _capSymbol :: String
- _capDesc :: String
- class ToParam (t :: k) where
- toParam :: Proxy t -> DocQueryParam
- data DocQueryParam = DocQueryParam {
- _paramName :: String
- _paramValues :: [String]
- _paramDesc :: String
- _paramKind :: ParamKind
- data ParamKind
- class ToAuthInfo (a :: k) where
- toAuthInfo :: Proxy a -> DocAuthentication
- data DocAuthentication = DocAuthentication {}
Parse Client
Arguments
:: HasCLI m api '[] | |
=> Proxy api | API |
-> Proxy m | Client monad |
-> InfoMod (m (CLIResult m api)) | Options for top-level display |
-> IO (m (CLIResult m api)) |
Parse a servant client; the result can be run. The choice of m
gives the backend you are using; for example, the default GHC
servant-client backend is ClientM
.
Returns the request response, which is usually a layer of Either
for
every endpoint branch. You can find the response type directly by using
typed holes or asking ghci with :t
or :kind! forall m. CLIResult
m MyAPI
. Because it might be tedious handling nested Either
s, see
parseHandleClient
for a way to handle each potential branch in
a convenient way.
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
.
Arguments
:: (HasCLI m api '[], Functor m) | |
=> Proxy api | API |
-> Proxy m | Client monad |
-> InfoMod (m (CLIResult m api)) | Options for top-level display |
-> CLIHandler m api r | Handler |
-> IO (m r) |
Parse a server client, like parseClient
. However, instead of that
client action returning the request response, instead use a CLIHandler
to handle every potential request response. It essentially lets you
specify how to sort each potential endpoint's response into a single
output value.
The handler is usually a :<|>
for every endpoint branch.
You can find it by using typed holes or asking ghci with :t
or :kind!
forall m r. CLIHandler m MyAPI r
.
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
.
With context
parseClientWithContext Source #
Arguments
:: HasCLI m api context | |
=> Proxy api | API |
-> Proxy m | Client monad |
-> Rec (ContextFor m) context | Extra context |
-> InfoMod (m (CLIResult m api)) | Options for top-level display |
-> IO (m (CLIResult m api)) |
A version of parseClient
that can be used if the API requires
any external context to generate runtime data.
parseHandleClientWithContext Source #
Arguments
:: forall m api context r. (HasCLI m api context, Functor m) | |
=> Proxy api | API |
-> Proxy m | Client monad |
-> Rec (ContextFor m) context | Extra context |
-> InfoMod (m (CLIResult m api)) | Options for top-level display |
-> CLIHandler m api r | Handler |
-> IO (m r) |
A version of parseHandleClient
that can be used if the API requires
any external context to generate runtime data.
Typeclasses
class HasCLI m api ctx where Source #
Typeclass defining how each API combinator influences how a server can be interacted with using command line options.
Note that query parameters and captures all require servant-docs annotation instances, to allow for proper help messages.
Unless you are adding new combinators to be used with APIs, you can ignore this class.
Minimal complete definition
Associated Types
type CLIResult (m :: Type -> Type) (api :: Type) :: Type Source #
The parsed type of the client request response. Usually this will
be a bunch of nested Either
s for every API endpoint, nested
according to the :<|>
s in the API.
type CLIHandler (m :: Type -> Type) (api :: Type) (r :: Type) :: Type Source #
The type of a data structure to conveniently handle the results of
all pontential endpoints. This is useful because it is often
tedious to handle the bunch of nested Either
s that CLIResult
has.
It essentially lets you specify how to sort each potential endpoint's response into a single output value.
Usually this will be a bunch of nested :<|>
s which handle each
endpoint, according to the :<|>
s in the API. It mirrors the
structure of Client
and ServerT
.
Used with functions like parseHandleClient
.
Methods
cliHandler :: Proxy m -> Proxy api -> Proxy ctx -> CLIHandler m api r -> CLIResult m api -> r Source #
Handle all the possibilities in a CLIResult
, by giving the
appropriate CLIHandler
.
Instances
HasCLI m EmptyAPI ctx Source # |
The branch ending in One can use |
Defined in Servant.CLI.HasCLI | |
RunClient m => HasCLI m Raw ctx Source # | Asks for method as a command line argument. If any |
Defined in Servant.CLI.HasCLI | |
(HasCLI m a ctx, HasCLI m b ctx, Functor m) => HasCLI m (a :<|> b) ctx Source # | Using alternation with |
Defined in Servant.CLI.HasCLI | |
(RunClient m, ReflectMethod method) => HasCLI m (NoContentVerb method) ctx Source # | Final actions are the result of specifying all necessary command line positional arguments. All command line options are associated with the final action at the end of their endpoint/path. They cannot be entered in "before" you arrive at your final endpoint. If more than one action (under a different method) exists
under the same endpoint/path, the method ( |
Defined in Servant.CLI.HasCLI Associated Types type CLIResult m (NoContentVerb method) Source # type CLIHandler m (NoContentVerb method) r Source # Methods cliPStructWithContext_ :: Proxy m -> Proxy (NoContentVerb method) -> Rec (ContextFor m) ctx -> PStruct (Request -> m (CLIResult m (NoContentVerb method))) Source # cliHandler :: Proxy m -> Proxy (NoContentVerb method) -> Proxy ctx -> CLIHandler m (NoContentVerb method) r -> CLIResult m (NoContentVerb method) -> r Source # | |
(KnownSymbol path, HasCLI m api ctx) => HasCLI m (path :> api) ctx Source # | A path component is interpreted as a "subcommand". |
Defined in Servant.CLI.HasCLI | |
HasCLI m api ctx => HasCLI m (HttpVersion :> api) ctx Source # | Using |
Defined in Servant.CLI.HasCLI Associated Types type CLIResult m (HttpVersion :> api) Source # type CLIHandler m (HttpVersion :> api) r Source # Methods cliPStructWithContext_ :: Proxy m -> Proxy (HttpVersion :> api) -> Rec (ContextFor m) ctx -> PStruct (Request -> m (CLIResult m (HttpVersion :> api))) Source # cliHandler :: Proxy m -> Proxy (HttpVersion :> api) -> Proxy ctx -> CLIHandler m (HttpVersion :> api) r -> CLIResult m (HttpVersion :> api) -> r Source # | |
(ToAuthInfo (BasicAuth realm usr), HasCLI m api ctx, BasicAuth realm usr ∈ ctx, Monad m) => HasCLI m (BasicAuth realm usr :> api) ctx Source # | Add Please use a secure connection! |
Defined in Servant.CLI.HasCLI Associated Types type CLIResult m (BasicAuth realm usr :> api) Source # type CLIHandler m (BasicAuth realm usr :> api) r Source # Methods cliPStructWithContext_ :: Proxy m -> Proxy (BasicAuth realm usr :> api) -> Rec (ContextFor m) ctx -> PStruct (Request -> m (CLIResult m (BasicAuth realm usr :> api))) Source # cliHandler :: Proxy m -> Proxy (BasicAuth realm usr :> api) -> Proxy ctx -> CLIHandler m (BasicAuth realm usr :> api) r -> CLIResult m (BasicAuth realm usr :> api) -> r Source # | |
(FromHttpApiData a, ToHttpApiData a, Typeable a, ToCapture (Capture sym a), HasCLI m api ctx) => HasCLI m (Capture' mods sym a :> api) ctx Source # | A Note that these require |
Defined in Servant.CLI.HasCLI Associated Types type CLIResult m (Capture' mods sym a :> api) Source # type CLIHandler m (Capture' mods sym a :> api) r Source # Methods cliPStructWithContext_ :: Proxy m -> Proxy (Capture' mods sym a :> api) -> Rec (ContextFor m) ctx -> PStruct (Request -> m (CLIResult m (Capture' mods sym a :> api))) Source # cliHandler :: Proxy m -> Proxy (Capture' mods sym a :> api) -> Proxy ctx -> CLIHandler m (Capture' mods sym a :> api) r -> CLIResult m (Capture' mods sym a :> api) -> r Source # | |
(FromHttpApiData a, ToHttpApiData a, Typeable a, ToCapture (CaptureAll sym a), HasCLI m api ctx) => HasCLI m (CaptureAll sym a :> api) ctx Source # | A |
Defined in Servant.CLI.HasCLI Associated Types type CLIResult m (CaptureAll sym a :> api) Source # type CLIHandler m (CaptureAll sym a :> api) r Source # Methods cliPStructWithContext_ :: Proxy m -> Proxy (CaptureAll sym a :> api) -> Rec (ContextFor m) ctx -> PStruct (Request -> m (CLIResult m (CaptureAll sym a :> api))) Source # cliHandler :: Proxy m -> Proxy (CaptureAll sym a :> api) -> Proxy ctx -> CLIHandler m (CaptureAll sym a :> api) r -> CLIResult m (CaptureAll sym a :> api) -> r Source # | |
(KnownSymbol desc, HasCLI m api ctx) => HasCLI m (Description desc :> api) ctx Source # |
|
Defined in Servant.CLI.HasCLI Associated Types type CLIResult m (Description desc :> api) Source # type CLIHandler m (Description desc :> api) r Source # Methods cliPStructWithContext_ :: Proxy m -> Proxy (Description desc :> api) -> Rec (ContextFor m) ctx -> PStruct (Request -> m (CLIResult m (Description desc :> api))) Source # cliHandler :: Proxy m -> Proxy (Description desc :> api) -> Proxy ctx -> CLIHandler m (Description desc :> api) r -> CLIResult m (Description desc :> api) -> r Source # | |
(KnownSymbol desc, HasCLI m api ctx) => HasCLI m (Summary desc :> api) ctx Source # |
|
Defined in Servant.CLI.HasCLI Associated Types type CLIResult m (Summary desc :> api) Source # type CLIHandler m (Summary desc :> api) r Source # Methods cliPStructWithContext_ :: Proxy m -> Proxy (Summary desc :> api) -> Rec (ContextFor m) ctx -> PStruct (Request -> m (CLIResult m (Summary desc :> api))) Source # cliHandler :: Proxy m -> Proxy (Summary desc :> api) -> Proxy ctx -> CLIHandler m (Summary desc :> api) r -> CLIResult m (Summary desc :> api) -> r Source # | |
(HasCLI m api ctx, AuthProtect tag ∈ ctx, Monad m) => HasCLI m (AuthProtect tag :> api) ctx Source # | Add Please use a secure connection! |
Defined in Servant.CLI.HasCLI Associated Types type CLIResult m (AuthProtect tag :> api) Source # type CLIHandler m (AuthProtect tag :> api) r Source # Methods cliPStructWithContext_ :: Proxy m -> Proxy (AuthProtect tag :> api) -> Rec (ContextFor m) ctx -> PStruct (Request -> m (CLIResult m (AuthProtect tag :> api))) Source # cliHandler :: Proxy m -> Proxy (AuthProtect tag :> api) -> Proxy ctx -> CLIHandler m (AuthProtect tag :> api) r -> CLIResult m (AuthProtect tag :> api) -> r Source # | |
(KnownSymbol sym, FromHttpApiData a, ToHttpApiData a, SBoolI (FoldRequired' 'False mods), Typeable a, HasCLI m api ctx) => HasCLI m (Header' mods sym a :> api) ctx Source # | A Like for |
Defined in Servant.CLI.HasCLI Associated Types type CLIResult m (Header' mods sym a :> api) Source # type CLIHandler m (Header' mods sym a :> api) r Source # Methods cliPStructWithContext_ :: Proxy m -> Proxy (Header' mods sym a :> api) -> Rec (ContextFor m) ctx -> PStruct (Request -> m (CLIResult m (Header' mods sym a :> api))) Source # cliHandler :: Proxy m -> Proxy (Header' mods sym a :> api) -> Proxy ctx -> CLIHandler m (Header' mods sym a :> api) r -> CLIResult m (Header' mods sym a :> api) -> r Source # | |
HasCLI m api ctx => HasCLI m (IsSecure :> api) ctx Source # | |
Defined in Servant.CLI.HasCLI Associated Types type CLIResult m (IsSecure :> api) Source # type CLIHandler m (IsSecure :> api) r Source # Methods cliPStructWithContext_ :: Proxy m -> Proxy (IsSecure :> api) -> Rec (ContextFor m) ctx -> PStruct (Request -> m (CLIResult m (IsSecure :> api))) Source # cliHandler :: Proxy m -> Proxy (IsSecure :> api) -> Proxy ctx -> CLIHandler m (IsSecure :> api) r -> CLIResult m (IsSecure :> api) -> r Source # | |
(KnownSymbol sym, ToParam (QueryFlag sym), HasCLI m api ctx) => HasCLI m (QueryFlag sym :> api) ctx Source # | Query flags are interpreted as command line flags/switches.
Note that these require |
Defined in Servant.CLI.HasCLI Associated Types type CLIResult m (QueryFlag sym :> api) Source # type CLIHandler m (QueryFlag sym :> api) r Source # Methods cliPStructWithContext_ :: Proxy m -> Proxy (QueryFlag sym :> api) -> Rec (ContextFor m) ctx -> PStruct (Request -> m (CLIResult m (QueryFlag sym :> api))) Source # cliHandler :: Proxy m -> Proxy (QueryFlag sym :> api) -> Proxy ctx -> CLIHandler m (QueryFlag sym :> api) r -> CLIResult m (QueryFlag sym :> api) -> r Source # | |
(KnownSymbol sym, FromHttpApiData a, ToHttpApiData a, SBoolI (FoldRequired' 'False mods), Typeable a, ToParam (QueryParam' mods sym a), HasCLI m api ctx) => HasCLI m (QueryParam' mods sym a :> api) ctx Source # | Query parameters are interpreted as command line options.
Note that these require |
Defined in Servant.CLI.HasCLI Associated Types type CLIResult m (QueryParam' mods sym a :> api) Source # type CLIHandler m (QueryParam' mods sym a :> api) r Source # Methods cliPStructWithContext_ :: Proxy m -> Proxy (QueryParam' mods sym a :> api) -> Rec (ContextFor m) ctx -> PStruct (Request -> m (CLIResult m (QueryParam' mods sym a :> api))) Source # cliHandler :: Proxy m -> Proxy (QueryParam' mods sym a :> api) -> Proxy ctx -> CLIHandler m (QueryParam' mods sym a :> api) r -> CLIResult m (QueryParam' mods sym a :> api) -> r Source # | |
(ToHttpApiData a, ToParam (QueryParams sym a), KnownSymbol sym, Typeable a, FromHttpApiData a, HasCLI m api ctx) => HasCLI m (QueryParams sym a :> api) ctx Source # | Query parameters are interpreted as command line options, and so repeated query parameters are repeated command line options.
Note that these require |
Defined in Servant.CLI.HasCLI Associated Types type CLIResult m (QueryParams sym a :> api) Source # type CLIHandler m (QueryParams sym a :> api) r Source # Methods cliPStructWithContext_ :: Proxy m -> Proxy (QueryParams sym a :> api) -> Rec (ContextFor m) ctx -> PStruct (Request -> m (CLIResult m (QueryParams sym a :> api))) Source # cliHandler :: Proxy m -> Proxy (QueryParams sym a :> api) -> Proxy ctx -> CLIHandler m (QueryParams sym a :> api) r -> CLIResult m (QueryParams sym a :> api) -> r Source # | |
HasCLI m api ctx => HasCLI m (RemoteHost :> api) ctx Source # | |
Defined in Servant.CLI.HasCLI Associated Types type CLIResult m (RemoteHost :> api) Source # type CLIHandler m (RemoteHost :> api) r Source # Methods cliPStructWithContext_ :: Proxy m -> Proxy (RemoteHost :> api) -> Rec (ContextFor m) ctx -> PStruct (Request -> m (CLIResult m (RemoteHost :> api))) Source # cliHandler :: Proxy m -> Proxy (RemoteHost :> api) -> Proxy ctx -> CLIHandler m (RemoteHost :> api) r -> CLIResult m (RemoteHost :> api) -> r Source # | |
(MimeRender ct a, ParseBody a, HasCLI m api ctx) => HasCLI m (ReqBody' mods (ct ': cts) a :> api) ctx Source # | Request body requirements are interpreted using Note if more than one |
Defined in Servant.CLI.HasCLI Associated Types type CLIResult m (ReqBody' mods (ct ': cts) a :> api) Source # type CLIHandler m (ReqBody' mods (ct ': cts) a :> api) r Source # Methods cliPStructWithContext_ :: Proxy m -> Proxy (ReqBody' mods (ct ': cts) a :> api) -> Rec (ContextFor m) ctx -> PStruct (Request -> m (CLIResult m (ReqBody' mods (ct ': cts) a :> api))) Source # cliHandler :: Proxy m -> Proxy (ReqBody' mods (ct ': cts) a :> api) -> Proxy ctx -> CLIHandler m (ReqBody' mods (ct ': cts) a :> api) r -> CLIResult m (ReqBody' mods (ct ': cts) a :> api) -> r Source # | |
(ToSourceIO chunk a, MimeRender ctype chunk, FramingRender framing, StreamBody' mods framing ctype a ∈ ctx, HasCLI m api ctx, Monad m) => HasCLI m (StreamBody' mods framing ctype a :> api) ctx Source # | As a part of |
Defined in Servant.CLI.HasCLI Associated Types type CLIResult m (StreamBody' mods framing ctype a :> api) Source # type CLIHandler m (StreamBody' mods framing ctype a :> api) r Source # Methods cliPStructWithContext_ :: Proxy m -> Proxy (StreamBody' mods framing ctype a :> api) -> Rec (ContextFor m) ctx -> PStruct (Request -> m (CLIResult m (StreamBody' mods framing ctype a :> api))) Source # cliHandler :: Proxy m -> Proxy (StreamBody' mods framing ctype a :> api) -> Proxy ctx -> CLIHandler m (StreamBody' mods framing ctype a :> api) r -> CLIResult m (StreamBody' mods framing ctype a :> api) -> r Source # | |
HasCLI m api ctx => HasCLI m (Vault :> api) ctx Source # | |
Defined in Servant.CLI.HasCLI | |
(NamedContext m name subctx ∈ ctx, HasCLI m subapi subctx) => HasCLI m (WithNamedContext name subctx subapi) ctx Source # | Descend down a subcontext indexed by a given name. Must be provided when parsing within the context. Useful for when you have multiple items with the same name within a context; this essentially creates a namespace for context items. |
Defined in Servant.CLI.HasCLI Associated Types type CLIResult m (WithNamedContext name subctx subapi) Source # type CLIHandler m (WithNamedContext name subctx subapi) r Source # Methods cliPStructWithContext_ :: Proxy m -> Proxy (WithNamedContext name subctx subapi) -> Rec (ContextFor m) ctx -> PStruct (Request -> m (CLIResult m (WithNamedContext name subctx subapi))) Source # cliHandler :: Proxy m -> Proxy (WithNamedContext name subctx subapi) -> Proxy ctx -> CLIHandler m (WithNamedContext name subctx subapi) r -> CLIResult m (WithNamedContext name subctx subapi) -> r Source # | |
(HasClient m (Verb method status cts' a), ReflectMethod method) => HasCLI m (Verb method status cts' a) ctx Source # | Final actions are the result of specifying all necessary command line positional arguments. All command line options are associated with the final action at the end of their endpoint/path. They cannot be entered in "before" you arrive at your final endpoint. If more than one action (under a different method) exists
under the same endpoint/path, the method ( |
Defined in Servant.CLI.HasCLI Associated Types type CLIResult m (Verb method status cts' a) Source # type CLIHandler m (Verb method status cts' a) r Source # Methods cliPStructWithContext_ :: Proxy m -> Proxy (Verb method status cts' a) -> Rec (ContextFor m) ctx -> PStruct (Request -> m (CLIResult m (Verb method status cts' a))) Source # cliHandler :: Proxy m -> Proxy (Verb method status cts' a) -> Proxy ctx -> CLIHandler m (Verb method status cts' a) r -> CLIResult m (Verb method status cts' a) -> r Source # | |
(RunStreamingClient m, MimeUnrender ct chunk, ReflectMethod method, FramingUnrender framing, FromSourceIO chunk a) => HasCLI m (Stream method status framing ct a) ctx Source # | Same semantics in parsing command line options as |
Defined in Servant.CLI.HasCLI Associated Types type CLIResult m (Stream method status framing ct a) Source # type CLIHandler m (Stream method status framing ct a) r Source # Methods cliPStructWithContext_ :: Proxy m -> Proxy (Stream method status framing ct a) -> Rec (ContextFor m) ctx -> PStruct (Request -> m (CLIResult m (Stream method status framing ct a))) Source # cliHandler :: Proxy m -> Proxy (Stream method status framing ct a) -> Proxy ctx -> CLIHandler m (Stream method status framing ct a) r -> CLIResult m (Stream method status framing ct a) -> r Source # |
Context
data family ContextFor (m :: Type -> Type) :: Type -> Type Source #
Data family associating API combinators with contexts required to run
them. These typically will be actions in m
that fetch/generate the
required data, and will only be "run" if the user selects an endpoint
that requires it through the command line interface.
Instances
newtype ContextFor m (BasicAuth realm usr) Source # | |
Defined in Servant.CLI.HasCLI | |
newtype ContextFor m (AuthProtect tag) Source # | |
Defined in Servant.CLI.HasCLI newtype ContextFor m (AuthProtect tag) = GenAuthReq {
| |
newtype ContextFor m (NamedContext m name subContext) Source # | |
Defined in Servant.CLI.HasCLI | |
newtype ContextFor m (StreamBody' mods framing ctype a) Source # | |
Defined in Servant.CLI.HasCLI |
newtype NamedContext m (name :: Symbol) (subContext :: [Type]) Source #
Contains a subcontext that can be descended down into using
NamedContext
. Mirrors NamedContext
.
Useful for when you have multiple items with the same name within a context; this essentially creates a namespace for context items.
Constructors
NamedContext (Rec (ContextFor m) subContext) |
Instances
newtype ContextFor m (NamedContext m name subContext) Source # | |
Defined in Servant.CLI.HasCLI |
descendIntoNamedContext :: forall (name :: Symbol) context subContext m. NamedContext m name subContext ∈ context => Proxy name -> Rec (ContextFor m) context -> Rec (ContextFor m) subContext Source #
Allows you to access NamedContext
s inside a context.
Lower-level
Create a structure for a command line parser.
This can be useful if you are combining functionality with existing
optparse-applicative parsers. You can convert a PStruct
to
a Parser
using structParser
.
cliPStructWithContext Source #
Arguments
:: HasCLI m api context | |
=> Proxy m | Client monad |
-> Proxy api | API |
-> Rec (ContextFor m) context | Extra context |
-> PStruct (m (CLIResult m api)) |
A version of cliPStruct
that can be used if the API requires
any external context to generate runtime data.
Arguments
:: 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
.
With context
Arguments
:: (HasCLI m api '[], Functor m) | |
=> Proxy m | Client monad |
-> Proxy api | API |
-> CLIHandler m api r | Handler |
-> PStruct (m r) |
Create a structure for a command line parser, producing results
according to a CLIHandler
. See parseHandleClient
for more
information.
This can be useful if you are combining functionality with existing
optparse-applicative parsers. You can convert a PStruct
to
a Parser
using structParser
.
cliHandlePStructWithContext Source #
Arguments
:: forall m api context r. (HasCLI m api context, Functor m) | |
=> Proxy m | Client monad |
-> Proxy api | API |
-> Rec (ContextFor m) context | Extra context |
-> CLIHandler m api r | Handler |
-> PStruct (m r) |
A version of cliHandlePStruct
that can be used if the API requires
any external context to generate runtime data.
Re-export
class ParseBody a where Source #
A helper class for defining directly how to parse request bodies. This allows more complex parsing of bodies.
You need an instance of this for every type you use with
ReqBody
.
Minimal complete definition
Nothing
Methods
Default implementation that expects a --data
option.
class ToCapture (c :: k) where #
The class that helps us automatically get documentation for URL captures.
Example of an instance:
instance ToCapture (Capture "name" Text) where toCapture _ = DocCapture "name" "name of the person to greet"
Methods
toCapture :: Proxy c -> DocCapture #
data DocCapture #
A type to represent captures. Holds the name of the capture and a description.
Write a ToCapture
instance for your captured types.
Constructors
DocCapture | |
Fields
|
Instances
Show DocCapture | |
Defined in Servant.Docs.Internal Methods showsPrec :: Int -> DocCapture -> ShowS # show :: DocCapture -> String # showList :: [DocCapture] -> ShowS # | |
Eq DocCapture | |
Defined in Servant.Docs.Internal | |
Ord DocCapture | |
Defined in Servant.Docs.Internal Methods compare :: DocCapture -> DocCapture -> Ordering # (<) :: DocCapture -> DocCapture -> Bool # (<=) :: DocCapture -> DocCapture -> Bool # (>) :: DocCapture -> DocCapture -> Bool # (>=) :: DocCapture -> DocCapture -> Bool # max :: DocCapture -> DocCapture -> DocCapture # min :: DocCapture -> DocCapture -> DocCapture # |
class ToParam (t :: k) where #
The class that helps us automatically get documentation for GET
(or other Method
) parameters.
Example of an instance:
instance ToParam (QueryParam' mods "capital" Bool) where toParam _ = DocQueryParam "capital" ["true", "false"] "Get the greeting message in uppercase (true) or not (false). Default is false."
Methods
toParam :: Proxy t -> DocQueryParam #
data DocQueryParam #
A type to represent a GET (or other possible Method
)
parameter from the Query String. Holds its name, the possible
values (leave empty if there isn't a finite number of them), and
a description of how it influences the output or behavior.
Write a ToParam
instance for your GET parameter types
Constructors
DocQueryParam | |
Fields
|
Instances
Show DocQueryParam | |
Defined in Servant.Docs.Internal Methods showsPrec :: Int -> DocQueryParam -> ShowS # show :: DocQueryParam -> String # showList :: [DocQueryParam] -> ShowS # | |
Eq DocQueryParam | |
Defined in Servant.Docs.Internal Methods (==) :: DocQueryParam -> DocQueryParam -> Bool # (/=) :: DocQueryParam -> DocQueryParam -> Bool # | |
Ord DocQueryParam | |
Defined in Servant.Docs.Internal Methods compare :: DocQueryParam -> DocQueryParam -> Ordering # (<) :: DocQueryParam -> DocQueryParam -> Bool # (<=) :: DocQueryParam -> DocQueryParam -> Bool # (>) :: DocQueryParam -> DocQueryParam -> Bool # (>=) :: DocQueryParam -> DocQueryParam -> Bool # max :: DocQueryParam -> DocQueryParam -> DocQueryParam # min :: DocQueryParam -> DocQueryParam -> DocQueryParam # |
Type of GET (or other Method
) parameter:
- Normal corresponds to
QueryParam
, i.e your usual GET parameter - List corresponds to
QueryParams
, i.e GET parameters with multiple values - Flag corresponds to
QueryFlag
, i.e a value-less GET parameter
Instances
Show ParamKind | |
Eq ParamKind | |
Ord ParamKind | |
class ToAuthInfo (a :: k) where #
The class that helps us get documentation for authenticated endpoints
Methods
toAuthInfo :: Proxy a -> DocAuthentication #
data DocAuthentication #
A type to represent Authentication information about an endpoint.
Constructors
DocAuthentication | |
Fields |
Instances
Show DocAuthentication | |
Defined in Servant.Docs.Internal Methods showsPrec :: Int -> DocAuthentication -> ShowS # show :: DocAuthentication -> String # showList :: [DocAuthentication] -> ShowS # | |
Eq DocAuthentication | |
Defined in Servant.Docs.Internal Methods (==) :: DocAuthentication -> DocAuthentication -> Bool # (/=) :: DocAuthentication -> DocAuthentication -> Bool # | |
Ord DocAuthentication | |
Defined in Servant.Docs.Internal Methods compare :: DocAuthentication -> DocAuthentication -> Ordering # (<) :: DocAuthentication -> DocAuthentication -> Bool # (<=) :: DocAuthentication -> DocAuthentication -> Bool # (>) :: DocAuthentication -> DocAuthentication -> Bool # (>=) :: DocAuthentication -> DocAuthentication -> Bool # max :: DocAuthentication -> DocAuthentication -> DocAuthentication # min :: DocAuthentication -> DocAuthentication -> DocAuthentication # |