Skip to content

donna-lang/argparse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

argparse

Donna argparse

Docs - Read

Test status

CLI argument parsing for the Donna programming language.

Overview

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.

Installation

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

Quick start

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 test

API

For API Reference visit the generated docs here

Argument forms

--flag        -> #("flag", "true")
--key value   -> #("key", "value")
--key=value   -> #("key", "value")
-v            -> #("v", "true")
-o out.txt    -> #("o", "out.txt")
file.txt      -> #("", "file.txt")

Licence

MIT

About

🧩 Argument parser for Donna

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages