ReadArgs-1.2.3: Simple command line argument parsing

Safe Haskell | Safe-Inferred
Language | Haskell98

ReadArgs

Synopsis

- readArgs :: ArgumentTuple a => IO a
- readArgsFrom :: ArgumentTuple a => [String] -> IO a
- class Arguable a where
  - parse :: String -> Maybe a
  - name :: a -> String
- class Argument a where
  - parseArg :: [String] -> [(a, [String])]
  - argName :: a -> String
- newtype NonGreedy (m :: Type -> Type) a = NonGreedy {
  - unNonGreedy :: m a
  }
- class ArgumentTuple a where
  - parseArgsFrom :: [String] -> Maybe a
  - usageFor :: a -> String
- data a :& b = a :& b

# Documentation

readArgs :: ArgumentTuple a => IO a Source #

parse the desired argument tuple from the command line or print a simple usage statment and quit

readArgsFrom :: ArgumentTuple a => [String] -> IO a Source #

read args from the given strings or print a simple usage statment and quit (so you can do option parsing first)

class Arguable a where Source #

a class for types that can be parsed from exactly one command line argument

Methods

parse :: String -> Maybe a Source #

name :: a -> String Source #

name's argument will usually be undefined, so when defining instances of Arguable, it should be lazy in its argument

#### Instances

Instances details

Arguable FilePath Source # | FilePath is a special case, so that we don't force the user to double-quote their input
Instance details Defined in ReadArgs Methods parse :: String -> Maybe FilePath Source # name :: FilePath -> String Source #
Arguable Text Source # | Text is a special case, so that we don't force the user to double-quote their input
Instance details Defined in ReadArgs Methods parse :: String -> Maybe Text Source # name :: Text -> String Source #
Arguable String Source # | string is a special case, so that we don't force the user to double-quote their input
Instance details Defined in ReadArgs Methods parse :: String -> Maybe String Source # name :: String -> String Source #
Arguable Char Source # | char is a special case, so that we don't force the user to single-quote their input
Instance details Defined in ReadArgs Methods parse :: String -> Maybe Char Source # name :: Char -> String Source #
(Typeable t, Read t) => Arguable t Source # | all types that are typeable and readable can be used as simple arguments
Instance details Defined in ReadArgs Methods parse :: String -> Maybe t Source # name :: t -> String Source #

class Argument a where Source #

a class for types that can be parsed from some number of command line arguments

Methods

parseArg :: [String] -> [(a, [String])] Source #

argName :: a -> String Source #

argName's argument will usually be undefined, so when defining instances of Arguable, it should be lazy in its argument

#### Instances

Instances details

Argument String Source # | make sure strings are handled as a separate type, not a list of chars
Instance details Defined in ReadArgs Methods parseArg :: [String] -> [(String, [String])] Source # argName :: String -> String Source #
Arguable a => Argument a Source # | use the arguable tyep to just parse a single argument
Instance details Defined in ReadArgs Methods parseArg :: [String] -> [(a, [String])] Source # argName :: a -> String Source #
Arguable a => Argument (Maybe a) Source # | use Maybe when it should be parsed from one or zero (greedily)
Instance details Defined in ReadArgs Methods parseArg :: [String] -> [(Maybe a, [String])] Source # argName :: Maybe a -> String Source #
Arguable a => Argument [a] Source # | use a list when it should be parsed from zero or more (greedily)
Instance details Defined in ReadArgs Methods parseArg :: [String] -> [([a], [String])] Source # argName :: [a] -> String Source #
Argument (m a) => Argument (NonGreedy m a) Source # | use NonGreedy when it should be parsed non-greedily (e.g. `(NonGreedy xs :: NonGreedy [] Int, x :: Maybe Float) <- readArgs`)
Instance details Defined in ReadArgs Methods parseArg :: [String] -> [(NonGreedy m a, [String])] Source # argName :: NonGreedy m a -> String Source #

newtype NonGreedy (m :: Type -> Type) a Source #

a wrapper type to indicate a non-greedy list or maybe

Constructors

NonGreedy |

Fields

- unNonGreedy :: m a

#### Instances

Instances details

Argument (m a) => Argument (NonGreedy m a) Source # | use NonGreedy when it should be parsed non-greedily (e.g. `(NonGreedy xs :: NonGreedy [] Int, x :: Maybe Float) <- readArgs`)
Instance details Defined in ReadArgs Methods parseArg :: [String] -> [(NonGreedy m a, [String])] Source # argName :: NonGreedy m a -> String Source #
Show (m a) => Show (NonGreedy m a) Source # |
Instance details Defined in ReadArgs Methods showsPrec :: Int -> NonGreedy m a -> ShowS Source # show :: NonGreedy m a -> String Source # showList :: [NonGreedy m a] -> ShowS Source #
Eq (m a) => Eq (NonGreedy m a) Source # |
Instance details Defined in ReadArgs Methods (==) :: NonGreedy m a -> NonGreedy m a -> Bool Source # (/=) :: NonGreedy m a -> NonGreedy m a -> Bool Source #

class ArgumentTuple a where Source #

a class for tuples of types that can be parsed from the entire list of arguments

Methods

parseArgsFrom :: [String] -> Maybe a Source #

usageFor :: a -> String Source #

usageFor's argument will usually be undefined, so when defining instances of Arguable, it should be lazy in its argument

#### Instances

Instances details

ArgumentTuple () Source # | use () for no arguments
Instance details Defined in ReadArgs Methods parseArgsFrom :: [String] -> Maybe () Source # usageFor :: () -> String Source #
Argument a => ArgumentTuple a Source # |
Instance details Defined in ReadArgs Methods parseArgsFrom :: [String] -> Maybe a Source # usageFor :: a -> String Source #
(Argument a, ArgumentTuple y) => ArgumentTuple (a :& y) Source # |
Instance details Defined in ReadArgs Methods parseArgsFrom :: [String] -> Maybe (a :& y) Source # usageFor :: (a :& y) -> String Source #
(Argument b, Argument a) => ArgumentTuple (b, a) Source # |
Instance details Defined in ReadArgs Methods parseArgsFrom :: [String] -> Maybe (b, a) Source # usageFor :: (b, a) -> String Source #
(Argument c, Argument b, Argument a) => ArgumentTuple (c, b, a) Source # |
Instance details Defined in ReadArgs Methods parseArgsFrom :: [String] -> Maybe (c, b, a) Source # usageFor :: (c, b, a) -> String Source #
(Argument d, Argument c, Argument b, Argument a) => ArgumentTuple (d, c, b, a) Source # |
Instance details Defined in ReadArgs Methods parseArgsFrom :: [String] -> Maybe (d, c, b, a) Source # usageFor :: (d, c, b, a) -> String Source #
(Argument e, Argument d, Argument c, Argument b, Argument a) => ArgumentTuple (e, d, c, b, a) Source # |
Instance details Defined in ReadArgs Methods parseArgsFrom :: [String] -> Maybe (e, d, c, b, a) Source # usageFor :: (e, d, c, b, a) -> String Source #
(Argument f, Argument e, Argument d, Argument c, Argument b, Argument a) => ArgumentTuple (f, e, d, c, b, a) Source # |
Instance details Defined in ReadArgs Methods parseArgsFrom :: [String] -> Maybe (f, e, d, c, b, a) Source # usageFor :: (f, e, d, c, b, a) -> String Source #
(Argument g, Argument f, Argument e, Argument d, Argument c, Argument b, Argument a) => ArgumentTuple (g, f, e, d, c, b, a) Source # |
Instance details Defined in ReadArgs Methods parseArgsFrom :: [String] -> Maybe (g, f, e, d, c, b, a) Source # usageFor :: (g, f, e, d, c, b, a) -> String Source #
(Argument h, Argument g, Argument f, Argument e, Argument d, Argument c, Argument b, Argument a) => ArgumentTuple (h, g, f, e, d, c, b, a) Source # |
Instance details Defined in ReadArgs Methods parseArgsFrom :: [String] -> Maybe (h, g, f, e, d, c, b, a) Source # usageFor :: (h, g, f, e, d, c, b, a) -> String Source #
(Argument i, Argument h, Argument g, Argument f, Argument e, Argument d, Argument c, Argument b, Argument a) => ArgumentTuple (i, h, g, f, e, d, c, b, a) Source # |
Instance details Defined in ReadArgs Methods parseArgsFrom :: [String] -> Maybe (i, h, g, f, e, d, c, b, a) Source # usageFor :: (i, h, g, f, e, d, c, b, a) -> String Source #
(Argument j, Argument i, Argument h, Argument g, Argument f, Argument e, Argument d, Argument c, Argument b, Argument a) => ArgumentTuple (j, i, h, g, f, e, d, c, b, a) Source # |
Instance details Defined in ReadArgs Methods parseArgsFrom :: [String] -> Maybe (j, i, h, g, f, e, d, c, b, a) Source # usageFor :: (j, i, h, g, f, e, d, c, b, a) -> String Source #
(Argument k, Argument j, Argument i, Argument h, Argument g, Argument f, Argument e, Argument d, Argument c, Argument b, Argument a) => ArgumentTuple (k, j, i, h, g, f, e, d, c, b, a) Source # |
Instance details Defined in ReadArgs Methods parseArgsFrom :: [String] -> Maybe (k, j, i, h, g, f, e, d, c, b, a) Source # usageFor :: (k, j, i, h, g, f, e, d, c, b, a) -> String Source #
(Argument l, Argument k, Argument j, Argument i, Argument h, Argument g, Argument f, Argument e, Argument d, Argument c, Argument b, Argument a) => ArgumentTuple (l, k, j, i, h, g, f, e, d, c, b, a) Source # |
Instance details Defined in ReadArgs Methods parseArgsFrom :: [String] -> Maybe (l, k, j, i, h, g, f, e, d, c, b, a) Source # usageFor :: (l, k, j, i, h, g, f, e, d, c, b, a) -> String Source #
(Argument m, Argument l, Argument k, Argument j, Argument i, Argument h, Argument g, Argument f, Argument e, Argument d, Argument c, Argument b, Argument a) => ArgumentTuple (m, l, k, j, i, h, g, f, e, d, c, b, a) Source # |
Instance details Defined in ReadArgs Methods parseArgsFrom :: [String] -> Maybe (m, l, k, j, i, h, g, f, e, d, c, b, a) Source # usageFor :: (m, l, k, j, i, h, g, f, e, d, c, b, a) -> String Source #
(Argument n, Argument m, Argument l, Argument k, Argument j, Argument i, Argument h, Argument g, Argument f, Argument e, Argument d, Argument c, Argument b, Argument a) => ArgumentTuple (n, m, l, k, j, i, h, g, f, e, d, c, b, a) Source # |
Instance details Defined in ReadArgs Methods parseArgsFrom :: [String] -> Maybe (n, m, l, k, j, i, h, g, f, e, d, c, b, a) Source # usageFor :: (n, m, l, k, j, i, h, g, f, e, d, c, b, a) -> String Source #
(Argument o, Argument n, Argument m, Argument l, Argument k, Argument j, Argument i, Argument h, Argument g, Argument f, Argument e, Argument d, Argument c, Argument b, Argument a) => ArgumentTuple (o, n, m, l, k, j, i, h, g, f, e, d, c, b, a) Source # |
Instance details Defined in ReadArgs Methods parseArgsFrom :: [String] -> Maybe (o, n, m, l, k, j, i, h, g, f, e, d, c, b, a) Source # usageFor :: (o, n, m, l, k, j, i, h, g, f, e, d, c, b, a) -> String Source #

data a :& b infixr 5 Source #

use :& to construct arbitrary length tuples of any parsable arguments

Constructors

a :& b infixr 5 |

#### Instances

Instances details

(Argument a, ArgumentTuple y) => ArgumentTuple (a :& y) Source # |
Instance details Defined in ReadArgs Methods parseArgsFrom :: [String] -> Maybe (a :& y) Source # usageFor :: (a :& y) -> String Source #
(Show a, Show b) => Show (a :& b) Source # |
Instance details Defined in ReadArgs Methods showsPrec :: Int -> (a :& b) -> ShowS Source # show :: (a :& b) -> String Source # showList :: [a :& b] -> ShowS Source #
(Eq a, Eq b) => Eq (a :& b) Source # |
Instance details Defined in ReadArgs Methods (==) :: (a :& b) -> (a :& b) -> Bool Source # (/=) :: (a :& b) -> (a :& b) -> Bool Source #