Safe Haskell | Safe |
---|---|
Language | Haskell98 |
A Command
provides a mode of operation of your program.
This allows a single program to provide many different pieces of
functionality. The first argument to the program (or the first few, if it
has subcommands) determines which command should be executed.
(darcs
and cabal
are examples of programs with this behaviour.)
An Action
represents an IO action, together with information about
applicable options and non-option arguments.
Synopsis
- type Commands m = Tree (Command m)
- data Tree a = Node a (Forest a)
- data Command m = Command {}
- command :: String -> String -> Action m -> Command m
- data Action m
- io :: MonadIO m => m () -> Action m
- withNonOption :: MonadIO m => Type x -> (x -> Action m) -> Action m
- withNonOptions :: MonadIO m => Type x -> ([x] -> Action m) -> Action m
- withOption :: MonadIO m => Option a -> (a -> Action m) -> Action m
- ignoreOption :: Option a -> Action m -> Action m
Documentation
type Commands m = Tree (Command m) Source #
Commands m
is a tree of commands (with action in the monad m
).
It represents the whole set of possible commands of a program.
Non-empty, possibly infinite, multi-way trees; also known as rose trees.
Instances
Monad Tree | |
Functor Tree | |
MonadFix Tree | Since: containers-0.5.11 |
Applicative Tree | |
Foldable Tree | |
Defined in Data.Tree fold :: Monoid m => Tree m -> m # foldMap :: Monoid m => (a -> m) -> Tree a -> m # foldr :: (a -> b -> b) -> b -> Tree a -> b # foldr' :: (a -> b -> b) -> b -> Tree a -> b # foldl :: (b -> a -> b) -> b -> Tree a -> b # foldl' :: (b -> a -> b) -> b -> Tree a -> b # foldr1 :: (a -> a -> a) -> Tree a -> a # foldl1 :: (a -> a -> a) -> Tree a -> a # elem :: Eq a => a -> Tree a -> Bool # maximum :: Ord a => Tree a -> a # | |
Traversable Tree | |
Eq1 Tree | Since: containers-0.5.9 |
Ord1 Tree | Since: containers-0.5.9 |
Read1 Tree | Since: containers-0.5.9 |
Show1 Tree | Since: containers-0.5.9 |
MonadZip Tree | |
Eq a => Eq (Tree a) | |
Data a => Data (Tree a) | |
Defined in Data.Tree gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Tree a -> c (Tree a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Tree a) # toConstr :: Tree a -> Constr # dataTypeOf :: Tree a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Tree a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Tree a)) # gmapT :: (forall b. Data b => b -> b) -> Tree a -> Tree a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Tree a -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Tree a -> r # gmapQ :: (forall d. Data d => d -> u) -> Tree a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Tree a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Tree a -> m (Tree a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Tree a -> m (Tree a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Tree a -> m (Tree a) # | |
Read a => Read (Tree a) | |
Show a => Show (Tree a) | |
Generic (Tree a) | |
NFData a => NFData (Tree a) | |
Generic1 Tree | |
type Rep (Tree a) | Since: containers-0.5.8 |
Defined in Data.Tree type Rep (Tree a) = D1 (MetaData "Tree" "Data.Tree" "containers-0.6.0.1" False) (C1 (MetaCons "Node" PrefixI True) (S1 (MetaSel (Just "rootLabel") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a) :*: S1 (MetaSel (Just "subForest") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Forest a)))) | |
type Rep1 Tree | Since: containers-0.5.8 |
Defined in Data.Tree type Rep1 Tree = D1 (MetaData "Tree" "Data.Tree" "containers-0.6.0.1" False) (C1 (MetaCons "Node" PrefixI True) (S1 (MetaSel (Just "rootLabel") NoSourceUnpackedness NoSourceStrictness DecidedLazy) Par1 :*: S1 (MetaSel (Just "subForest") NoSourceUnpackedness NoSourceStrictness DecidedLazy) ([] :.: Rec1 Tree))) |
A Command m
is an action (in the monad m
), together with some
descriptive information.
command :: String -> String -> Action m -> Command m Source #
Create a new command having a given name and action.
An Action m
is an action (in the monad m
), which may take arguments
("non-options") and options from the command line.
io :: MonadIO m => m () -> Action m Source #
A simple action, taking no argument, and having no options.
withNonOption :: MonadIO m => Type x -> (x -> Action m) -> Action m Source #
Create an action that takes an argument (non-option).
The type of argument is specified by the first parameter; such values can be obtained from the module System.Console.Argument.
withNonOptions :: MonadIO m => Type x -> ([x] -> Action m) -> Action m Source #
Create an action that takes all remaining non-option arguments.
The type of arguments is specified by the first parameter; such values can be obtained from the module System.Console.Argument.
withOption :: MonadIO m => Option a -> (a -> Action m) -> Action m Source #
Create an action that takes an option.
The first parameter is a description of the option; such a value can be
constructed using option
.
ignoreOption :: Option a -> Action m -> Action m Source #
Create an action that allows, but ignores, the given option.
This is especially useful if this option is given in the configuration file, but is meant for other commands; then this action will not give an error message about an unrecognised option.