CLI.Parser
A module for parsing arguments from the command line. With this you can turn the following
mycmd greet --overwrite file.txt
Into a data structure.
mycmd
is the Applicationgreet
is the Command--overwrite
is a Flagfile.txt
is an Argument
Application
Defines a command line application.
name
is the name of the applicationversion
is the application versioncommands
is a group of commands that this application recognizesintro
andoutro
is used when the user calls the application without any arguments. They define what text comes before and after the list of supported commands.
Takes input from the user in the form of an Array
of String
, and parses it according
to the given App
definition.
Groups
A parser for a group, or collection, of commands.
Definition of a command.
The result of parsing user input.
Defines an empty group of commands. To add commands to this group, you'll need to use withCommand and withPrefix.
Returns a new group that contains the given command. If there are multiple
commands in the group with the same word
, then the last registered command
wins.
Embeds a group of commands into an existing group, accessible by the given prefix.
Arguments
Defines an argument value. The fn
property is the function that parses
the String
representation of an argument into its final form.
Arguments are values that a Command requires to function. An ArgumentParser
is a way of converting an arbitrary number of String
inputs into Gren values.
There are mainly two things that can go wrong when parsing arguments. You can either get an unexpected number of arguments or one or more of those arguments may fail to parse.
Turns an ArgumentParserError into a prettified String
.
Some Commands doesn't require arguments. This parser checks that exactly 0 arguments were provided.
Parses exactly one argument.
Parses exactly two arguments.
Parses exactly three arguments.
Parses zero or more arguments of a single type.
Maps a successfully parsed set of arguments into something else.
A list of parsers that will be tried one after another until one succeeds.
Flags
Flags are prefixed with --
and are meant to customize a command.
There are several things that can go wrong when parsing flags:
- The parser can find an associated value for a flag that requires none.
- The parser might not find an associated value for a flag that does require one.
- The associated value might fail to parse.
- The flag might be unknown.
Returns a prettified error message for the given FlagParserError.
A parser that verifies that no flags have been provided.
Defines an empty group of flags. You'll need to register flags using the toggle and flag functions.
Defines a flag that doesn't require an associated value. We're simply checking if the flag is present or not.
Defines a flag that requires an associated value.
Common parsers
Parses a String
into a FileSystem.Path
.
Like pathParser, but verifies that the file extension is .gren
.