Skip to content
FutureBlitz

    Install

    Import std.os.args

    ArgsParser

    std.os.args

    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")

    std/os/args.fb, line 145

    • Public New(name: String, about: String = "", version: String = "") constructor #

      A new ArgsParser for the program name, which --help describes by about and --version shows version for.

    • @PanicsAtCaller Public Method Flag(key: String, long: String = "", short: String = "", help: String = "", counts: Bool = False): ArgsParser method #

      A flag, "--long" or "-s", which is True once given, or with counts, how many times it was. Panics for a key, long name, or short name 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 = ""): ArgsParser method #

      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): ArgsParser method #

      The next argument by its place, which with rest takes all that are left. Panics for one after one that takes the rest, 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): ArgsParser method #

      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 is optional. Panics beside positional arguments, or for a name another command has.

    • Public Method Parse(arguments: String[]): Value Throws ArgumentError method #

      Reads arguments into 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.

    • Public Method Usage(): String method #

      How the program is run, as the help's first line has it.

    • Public Method Help(): String method #

      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.