butcher-1.3.3.2: Chops a command or program invocation into digestable pieces.

Safe Haskell | None
Language | Haskell2010

UI.Butcher.Monadic.Flag

Description

Flags are arguments to your current command that are prefixed with "-" or "--", for example "-v" or "--verbose". These flags can have zero or one argument. (Butcher internally has more general concept of CmdPart that could handle any number of arguments, so take this as what this module aims to provide, not what you could theoretically implement on top of butcher).

Synopsis

- data Flag p = Flag {
  - _flag_help :: Maybe Doc
  - _flag_default :: Maybe p
  - _flag_visibility :: Visibility
  }
- flagHelp :: Doc -> Flag p
- flagHelpStr :: String -> Flag p
- flagDefault :: p -> Flag p
- flagHidden :: Flag p
- addSimpleBoolFlag :: Applicative f => String -> [String] -> Flag Void -> CmdParser f out Bool
- addSimpleCountFlag :: Applicative f => String -> [String] -> Flag Void -> CmdParser f out Int
- addSimpleFlagA :: String -> [String] -> Flag Void -> f () -> CmdParser f out ()
- addFlagReadParam :: forall f p out. (Applicative f, Typeable p, Read p, Show p) => String -> [String] -> String -> Flag p -> CmdParser f out p
- addFlagReadParams :: forall f p out. (Applicative f, Typeable p, Read p, Show p) => String -> [String] -> String -> Flag p -> CmdParser f out [p]
- addFlagStringParam :: forall f out. Applicative f => String -> [String] -> String -> Flag String -> CmdParser f out String
- addFlagStringParams :: forall f out. Applicative f => String -> [String] -> String -> Flag Void -> CmdParser f out [String]

# Documentation

data Flag p Source #

flag-description monoid. You probably won't need to use the constructor; mzero or any (<>) of flag(Help|Default) works well.

Constructors

Flag |

Fields

- _flag_help :: Maybe Doc
- _flag_default :: Maybe p
- _flag_visibility :: Visibility

#### Instances

Instances details

Semigroup (Flag p) Source # |
Instance details Defined in UI.Butcher.Monadic.Flag Methods (<>) :: Flag p -> Flag p -> Flag p sconcat :: NonEmpty (Flag p) -> Flag p stimes :: Integral b => b -> Flag p -> Flag p
Monoid (Flag p) Source # |
Instance details Defined in UI.Butcher.Monadic.Flag Methods mempty :: Flag p mappend :: Flag p -> Flag p -> Flag p mconcat :: [Flag p] -> Flag p

flagHelp :: Doc -> Flag p Source #

Create a `Flag` with just a help text.

flagHelpStr :: String -> Flag p Source #

Create a `Flag` with just a help text.

flagDefault :: p -> Flag p Source #

Create a `Flag` with just a default value.

flagHidden :: Flag p Source #

Create a `Flag` marked as hidden. Similar to hidden commands, hidden flags will not included in pretty-printing (help, usage etc.)

This feature is not well tested yet.

addSimpleBoolFlag Source #

Arguments

:: Applicative f |
=> String | short flag chars, i.e. "v" for -v
-> [String] | list of long names, e.g. ["verbose"]
-> Flag Void | properties
-> CmdParser f out Bool |

A no-parameter flag where non-occurence means False, occurence means True.

addSimpleCountFlag Source #

Arguments

:: Applicative f |
=> String | short flag chars, i.e. "v" for -v
-> [String] | list of long names, i.e. ["verbose"]
-> Flag Void | properties
-> CmdParser f out Int |

A no-parameter flag that can occur multiple times. Returns the number of occurences (0 or more).

addSimpleFlagA Source #

Arguments

:: String | short flag chars, i.e. "v" for -v
-> [String] | list of long names, e.g. ["verbose"]
-> Flag Void | properties
-> f () | action to execute whenever this matches
-> CmdParser f out () |

Applicative-enabled version of `addSimpleFlag`

addFlagReadParam Source #

Arguments

:: forall f p out. (Applicative f, Typeable p, Read p, Show p) |
=> String | short flag chars, i.e. "v" for -v
-> [String] | list of long names, i.e. ["verbose"]
-> String | param name
-> Flag p | properties
-> CmdParser f out p |

One-argument flag, where the argument is parsed via its Read instance.

addFlagReadParams Source #

Arguments

:: forall f p out. (Applicative f, Typeable p, Read p, Show p) |
=> String | short flag chars, i.e. "v" for -v
-> [String] | list of long names, i.e. ["verbose"]
-> String | param name
-> Flag p | properties
-> CmdParser f out [p] |

One-argument flag, where the argument is parsed via its Read instance. This version can accumulate multiple values by using the same flag with different arguments multiple times.

E.g. "--foo 3 --foo 5" yields [3,5].

addFlagStringParam Source #

Arguments

:: forall f out. Applicative f |
=> String | short flag chars, i.e. "v" for -v
-> [String] | list of long names, i.e. ["verbose"]
-> String | param name
-> Flag String | properties
-> CmdParser f out String |

One-argument flag where the argument can be an arbitrary string.

addFlagStringParams Source #

Arguments

:: forall f out. Applicative f |
=> String | short flag chars, i.e. "v" for -v
-> [String] | list of long names, i.e. ["verbose"]
-> String | param name
-> Flag Void | properties
-> CmdParser f out [String] |

One-argument flag where the argument can be an arbitrary string. This version can accumulate multiple values by using the same flag with different arguments multiple times.

E.g. "--foo abc --foo def" yields ["abc", "def"].