Import std.os.args
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)-
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.
-
Reads
argumentsinto a T. Throws an ArgsHelp for --help, -h, --version, and -V, and an ArgsError for what it can't read, which says why. -
The ArgsParser that
Parse<T>reads with, made from T's Fields' attributes. -
What --help prints for a T.
Report an issue with this page or with FutureBlitz on GitHub.