Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CLI - Ecko Std Lib Package

Command-line argument parsing for Ecko, written in Ecko: typed flags, options, positionals, defaults, and generated usage.

Install

ecko get github.com/ecko-lang/cli

Usage

import cli
import std.os

spec = cli.parser("greet", "print a friendly greeting")
  |> cli.flag("--loud", "shout it")
  |> cli.opt("--count", { kind: "int", default: 1, help: "repeat N times" })
  |> cli.arg("name", { required: true })

args = cli.parse(spec, os.args())   # { loud: bool, count: int, name: string }
print(cli.usage(spec))              # generated help text

API

Function Description
parser(name, description?) Start a parser spec
flag(spec, name, help?) A boolean flag (--loud)
opt(spec, name, opts?) An option taking a value. opts: { kind: "string"|"int"|"float"|"bool", default, help }
arg(spec, name, opts?) A positional. opts: { required, help }
parse(spec, argv) Parse a list of args → a map of values, or raise a kind-"cli" error
usage(spec) Generated help text

flag/opt/arg return a new spec, so they chain with |>. Options accept both --count 3 and --count=3. Result keys are the names without dashes.

Testing

ecko test tests/

License

MIT - see LICENSE.

About

Argparse-grade command-line argument parsing for Ecko.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors