harg-0.4.0.0: Haskell program configuration using higher kinded data

Safe HaskellNone
LanguageHaskell2010

Options.Harg.Subcommands

Synopsis

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) = mapSubcommand sources opts
  parser = subparser (mconcat commands)
  ...

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) -> ([OptError], [Mod CommandFields (VariantF xs f)]) Source #

Instances
ExplSubcommands Z ts xs ([] :: [(Type -> Type) -> Type]) => Subcommands ts xs Source # 
Instance details

Defined in Options.Harg.Subcommands

Methods

mapSubcommand :: (All (RunSource s) xs, Applicative f) => s -> AssocListF ts xs (Compose Opt f) -> ([OptError], [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) -> ([OptError], [Mod CommandFields (VariantF (acc ++ xs) f)]) Source #

Instances
ExplSubcommands n ([] :: [Symbol]) ([] :: [(Type -> Type) -> Type]) acc Source # 
Instance details

Defined in Options.Harg.Subcommands

Methods

explMapSubcommand :: (All (RunSource s) [], Applicative f) => SNat n -> s -> AssocListF [] [] (Compose Opt f) -> ([OptError], [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 # 
Instance details

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) -> ([OptError], [Mod CommandFields (VariantF (as ++ (x ': xs)) f)]) Source #