CLI argument parsing for the Donna programming language.
argparse converts command-line arguments into simple #(String, String) pairs.
It supports long flags, long named values, --key=value arguments, short flags, short named values, and positional arguments.
Add to your donna.toml as a dependency:
[dependencies]
argparse = { git = "https://github.com/donna-lang/argparse", version = ">=0.1.0 and <1.0.0" }Then import the module:
import argparse
import argparse
pub fn main() -> Nil:
let args = argparse.from_argv()
let output = argparse.get(args, "output")
let verbose = argparse.has(args, "verbose")
let files = argparse.positional(args)
echo output
For tests or custom parsing, use parse directly:
import argparse
pub fn parse_example() -> String:
let args = argparse.parse(["--output=site", "--verbose", "content.md"])
argparse.get(args, "output")
Run:
donna testFor API Reference visit the generated docs here
--flag -> #("flag", "true")
--key value -> #("key", "value")
--key=value -> #("key", "value")
-v -> #("v", "true")
-o out.txt -> #("o", "out.txt")
file.txt -> #("", "file.txt")
MIT