Skip to content
FutureBlitz

    Install

    Import std.os.args

    Args

    std.os.args

    struct

    Public Struct Args

    Parsing the program's command-line arguments into a Struct of its options, and their help.

    Examples

    @Program(About: "Copies files.")
    Struct Options
        @Positional(Help: "What to copy")
        Field Source: String
        @Option(Help: "How many copies", Short: "n")
        Field Count: Int = 1
        @Flag(Help: "Says what it does", Short: "v")
        Field Verbose: Bool
    End Struct
    
    Local options = Try Args.Parse<Options>(["notes.txt", "-n", "3", "--verbose"])
    Expect(options.Source == "notes.txt" && options.Count == 3 && options.Verbose)
    Expect(ExpectThrows<ArgsError>(Args.Parse<Options>(["--colour"])) != Null)

    std/os/args.fb, line 617

    • Public Static Method Parse<T>(): T static method #

      Reads the program's command line into a T. --help, -h, --version, and -V print what they ask for, and a command line it can't read prints why, with how the program is run, to stderr; either way the program then ends, with 0 or 2.

    • Public Static Method Parse<T>(arguments: String[]): T Throws ArgumentError static method #

      Reads arguments into a T. Throws an ArgsHelp for --help, -h, --version, and -V, and an ArgsError for what it can't read, which says why.

    • Public Static Method Parser<T>(): ArgsParser static method #

      The ArgsParser that Parse<T> reads with, made from T's Fields' attributes.

    • Public Static Method Help<T>(): String static method #

      What --help prints for a T.

    Report an issue with this page or with FutureBlitz on GitHub.