Module

Node.Optlicative

Package
purescript-optlicative
Repository
Thimoteus/purescript-optlicative

#throw Source

throw :: forall a. OptError -> Optlicative a

A combinator that always fails.

#flag Source

flag :: String -> Maybe Char -> Optlicative Boolean

Check whether a boolean value appears as an option. This combinator cannot fail, as absence of its option is interpreted as false. The first argument is the expected name, the second is an optional character for single-hyphen style: For example, boolean "optimize" (Just 'O') will parse both --optimize and -O.

#string Source

string :: String -> Maybe ErrorMsg -> Optlicative String

Check whether a string appears as an option. The first argument is the expected name, the second is a custom error message if the option does not appear. A default error message is provided if this argument is Nothing.

#int Source

int :: String -> Maybe ErrorMsg -> Optlicative Int

Check whether an integer appears as an option. Arguments are the same as for string.

#float Source

float :: String -> Maybe ErrorMsg -> Optlicative Number

Check whether a float appears as an option. Arguments are the same as for string. Note that numbers without decimal points will still parse as floats.

#optional Source

optional :: forall a. Optlicative a -> Optlicative (Maybe a)

Instead of failing, turns an optlicative parser into one that always succeeds but may do so with Nothing if no such option is found. This is useful for --help flags in particular: Without this combinator, it's easy to make an Optlicative that gives an unhelpful MissingOpt error message when all the user did was try to find help text for a command.

#withDefault Source

withDefault :: forall a. a -> Optlicative a -> Optlicative a

Instead of failing, turns an optlicative parser into one that always succeeds but may do so with the given default argument if no such option is found.

#withDefaultM Source

withDefaultM :: forall m. Monoid m => Optlicative m -> Optlicative m

Like withDefault but the default value is mempty.

#optF Source

optF :: forall a. (String -> F a) -> String -> Maybe ErrorMsg -> Optlicative a

Given a deserializing function, returns the value if no errors were encountered during deserialization. If there were errors, they are turned into OptErrors.

#optForeign Source

optForeign :: String -> Maybe ErrorMsg -> Optlicative Foreign

Check whether something appears as an option, and coerce it to Foreign if it does. This can be used to parse a JSON argument, for example.

#many Source

many :: forall a. Optlicative a -> Optlicative (List a)

Apply an Optlicative parser zero or more times, collecting the results in a List.

#manyF Source

manyF :: forall a. (String -> F a) -> Int -> String -> Maybe ErrorMsg -> Optlicative (List a)

Given a deserializing function and the number of args to parse, none of which may start with a '-' character, returns a list of parsed values.

#optlicate Source

optlicate :: forall a optrow. Commando optrow a => Record optrow -> Preferences a -> Effect { cmd :: Maybe String, value :: Value a }

Use this to run an Optlicative.

#defaultPreferences Source

defaultPreferences :: Preferences Void

A Preferences that errors on unrecognized options, has no usage text, and uses an always-failing parser for global options.

#renderErrors Source

renderErrors :: List OptError -> String

A convenience function for nicely printing error messages.

Re-exports from Node.Commando

#Opt Source

data Opt (a :: Type) (row :: Row Type)

Constructors

Instances

#Commando Source

class Commando (row :: Row Type) a  where

Members

Instances

#endOpt Source

endOpt :: forall a. Optlicative a -> Opt a ()

Re-exports from Node.Optlicative.Types

#Value Source

type Value a = V (List OptError) a

#Preferences Source

type Preferences a = { errorOnUnrecognizedOpts :: Boolean, globalOpts :: Optlicative a, usage :: Maybe String }

#ErrorMsg Source