Import std.os.args
ArgsParser
class
Public Class ArgsParser
Reads a command line into a Value's Object: each flag's Bool or count, each option's and positional argument's String, or Array of them, and a command's Object, by their keys. Its methods give the ArgsParser back, so they chain.
Examples
Local parser = ArgsParser("tool").Flag("verbose", "verbose", "v").Positional("file")
Local value = Try parser.Parse(["-v", "notes.txt"])
Expect(value.Path("verbose")?.AsBool() == True)
Expect(value.Path("file")?.AsString() == "notes.txt")-
A new ArgsParser for the program
name, which --help describes byaboutand --version showsversionfor. -
@PanicsAtCaller Public Method Flag(key: String, long: String = "", short: String = "", help: String = "", counts: Bool = False): ArgsParsermethod #A flag, "--long" or "-s", which is True once given, or with
counts, how many times it was. Panics for a key,longname, orshortname another has, a short name that isn't one ASCII letter or digit, or neither name. -
@PanicsAtCaller Public Method Option(key: String, long: String = "", short: String = "", help: String = "", valueName: String = "", required: Bool = False, repeated: Bool = False, shownDefault: String = ""): ArgsParsermethod #An option that takes a value, "--long value", "--long=value", "-s value", or "-svalue", which can be given once, or with
repeated, any number of times. Panics as Flag does. -
@PanicsAtCaller Public Method Positional(key: String, help: String = "", valueName: String = "", required: Bool = True, rest: Bool = False): ArgsParsermethod #The next argument by its place, which with
resttakes all that are left. Panics for one after one that takes therest, a required one after one that isn't, or one beside commands. -
@PanicsAtCaller Public Method Command(name: String, key: String, parser: ArgsParser, help: String = "", optional: Bool = False): ArgsParsermethod #A command, which reads the rest of the command line after its name, into an Object at its
key. One of the commands has to be given, unless every one isoptional. Panics beside positional arguments, or for a name another command has. -
Reads
argumentsinto an Object. Throws an ArgsHelp for --help or -h, or --version or -V where there's a version, and an ArgsError for what it can't read, which says why. -
How the program is run, as the help's first line has it.
-
What --help prints: what the program does, how it's run, and each argument, option, and command, with what it does.
Report an issue with this page or with FutureBlitz on GitHub.