目录

moonbit-argkit

moonbit-argkit is a small command line argument parser written in MoonBit. It is meant for examples, teaching projects, and small CLI tools that need flags without pulling in a large framework.

Features

  • short flags: -v
  • long flags: --verbose
  • options with values: --output dist
  • inline option values: --output=dist
  • required option checks
  • default values
  • positional arguments
  • -- separator handling
  • schema validation and user-facing error reports
  • parse summaries for demos and small tools
  • typed values for integers, booleans, and enum-like choices
  • subcommand helpers
  • short flag bundles such as -abc
  • negative booleans such as --no-color
  • simple config/env layering helpers
  • shell completion, diagnostics, and Markdown/manpage rendering helpers
  • generated help text

Install

After publishing, install with:

moon add cauchyQ/moonbit-argkit@0.1.0

For local development:

moon check
moon test
moon run cmd/demo

Example

let args = ["--input", "data.txt", "-v", "row1"]
debug_inspect(has(args, "verbose", "v"), content="true")
debug_inspect(value(args, "input", "i"), content="Some(\"data.txt\")")
debug_inspect(value_or(args, "output", "o", "out.txt"), content="out.txt")
debug_inspect(
  positionals(args, ["input"], ["i"], ["verbose"], ["v"]),
  content="[\"row1\"]",
)

Schema validation:

let args = ["--input=data.txt", "-v", "row1"]
debug_inspect(
  validation_report(
    args,
    ["input"],
    ["i"],
    ["input"],
    ["i"],
    ["verbose"],
    ["v"],
  ),
  content="\"ok\"",
)
debug_inspect(
  parse_summary(args, ["input"], ["i"], ["verbose"], ["v"]),
  content="[\"value:input=data.txt\", \"flag:verbose=true\", \"arg:row1\"]",
)

Help text:

println(help_text(
  "demo",
  "read rows from an input file",
  ["input", "output"],
  ["i", "o"],
  ["input file", "output file"],
  ["verbose"],
  ["v"],
  ["print extra logs"],
))

License

MIT

关于
61.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9 京公网安备 11010802047560号