| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Options.Harg.Subcommands
Synopsis
- class Subcommands (ts :: [Symbol]) (xs :: [(Type -> Type) -> Type]) where
- mapSubcommand :: (All (RunSource s) xs, Applicative f) => s -> AssocListF ts xs (Compose Opt f) -> ([SourceRunError], [Mod CommandFields (VariantF xs f)])
- class ExplSubcommands (n :: Nat) (ts :: [Symbol]) (xs :: [(Type -> Type) -> Type]) (acc :: [(Type -> Type) -> Type]) where
- explMapSubcommand :: (All (RunSource s) xs, Applicative f) => SNat n -> s -> AssocListF ts xs (Compose Opt f) -> ([SourceRunError], [Mod CommandFields (VariantF (acc ++ xs) f)])
Documentation
class Subcommands (ts :: [Symbol]) (xs :: [(Type -> Type) -> Type]) where Source #
This class can be used with an AssocList. It returns the appropriate
list of CommandFields in order to create a subcommand parser.
Given the sources to use and the association list between the command string
and the command type, it returns the list of command field modifiers and a
list of errors.
The result can be used as follows:
... (errs, commands) =mapSubcommandsources opts parser =subparser(mconcatcommands) ...
In order to be able to create a subcommand parser for a heterogeneous list
of options (rather than a sum with different constructors), the return type
should also be heterogeneous. Here, we return a Variant, which is a more
generic version of Either. In order to do that, mapSubcommand traverses
the association list and creates an injection into the Variant, according to
the current position. So an AssocList like this:
opts :: AssocList '["run", "test"] '[RunConfig, TestConfig] Opt opts = ...
Should return VariantF '[RunConfig, TestConfig] Identity. In order to do
that, it will inject RunConfig based on its position (0) using HereF,
and TestConfig using ThereF . HereF because its position is 1.
Methods
mapSubcommand :: (All (RunSource s) xs, Applicative f) => s -> AssocListF ts xs (Compose Opt f) -> ([SourceRunError], [Mod CommandFields (VariantF xs f)]) Source #
Instances
| ExplSubcommands Z ts xs ([] :: [(Type -> Type) -> Type]) => Subcommands ts xs Source # | |
Defined in Options.Harg.Subcommands Methods mapSubcommand :: (All (RunSource s) xs, Applicative f) => s -> AssocListF ts xs (Compose Opt f) -> ([SourceRunError], [Mod CommandFields (VariantF xs f)]) Source # | |
class ExplSubcommands (n :: Nat) (ts :: [Symbol]) (xs :: [(Type -> Type) -> Type]) (acc :: [(Type -> Type) -> Type]) where Source #
More general version of Subcommands.
Methods
explMapSubcommand :: (All (RunSource s) xs, Applicative f) => SNat n -> s -> AssocListF ts xs (Compose Opt f) -> ([SourceRunError], [Mod CommandFields (VariantF (acc ++ xs) f)]) Source #
Instances
| ExplSubcommands n ([] :: [Symbol]) ([] :: [(Type -> Type) -> Type]) acc Source # | |
Defined in Options.Harg.Subcommands Methods explMapSubcommand :: (All (RunSource s) [], Applicative f) => SNat n -> s -> AssocListF [] [] (Compose Opt f) -> ([SourceRunError], [Mod CommandFields (VariantF (acc ++ []) f)]) Source # | |
| (ExplSubcommands (S n) ts xs (as ++ (x ': ([] :: [(Type -> Type) -> Type]))), InjectPosF n x (as ++ (x ': xs)), TraversableB x, ProductB x, KnownSymbol t, Proof as x xs) => ExplSubcommands n (t ': ts) (x ': xs) as Source # | |
Defined in Options.Harg.Subcommands Methods explMapSubcommand :: (All (RunSource s) (x ': xs), Applicative f) => SNat n -> s -> AssocListF (t ': ts) (x ': xs) (Compose Opt f) -> ([SourceRunError], [Mod CommandFields (VariantF (as ++ (x ': xs)) f)]) Source # | |