Sign in

    ArgParser

    command line argument parser

    utils
    command line
    parser
    Download zip
    Author
    Version
    0.1.10
    License
    Apache-2.0
    Last updated
    last year
    Downloads
    107K

    #ArgParser

    A simple command-line parser for MoonBit. It uses a declarative style to specify the command-line interface.

    #Usage

    test {
    let argv = ["-o", "out.mbt", "file1", "file2", "--verbose"]
    let verbose = @ref.new(false)
    let output = @ref.new("output")
    let files = []
    let usage =
    #| Simple CLI tool
    #| usage:
    #| mytool [options] <file1> [<file2>] ... -o <output>
    #|
    @ArgParser.parse(
    [
    ("--verbose", "-v", Set(verbose), "enable verbose message"),
    ("--output", "-o", Set_string(output), "output file name"),
    ],
    file => files.push(file),
    usage,
    argv,
    )
    inspect(verbose.val, content="true")
    inspect(output.val, content="out.mbt")
    inspect(files[0], content="file1")
    inspect(files[1], content="file2")
    }

    #help options

    ArgParser will automatically generate --help and -h options.

    #Related Libraries

    Looking for more powerful CLI tool? Check out clap.

    Spec

    pub(all) enum Spec {
    Unit(() -> Unit)
    String((String) -> Unit)
    Set_string(Ref[String])
    Set(Ref[Bool])
    Clear(Ref[Bool])
    }

    Matched option handler that used to interpret options.

    Unit - handle with callback

    String - handle associated value with callback

    Set_string - set option to associated value

    Set - set reference to true

    Clear - set reference to false

    parse

    fn parse(speclist : Array[(String, String, Spec, String)], rest : (String) -> Unit, usage_msg : String, argv : Array[String]) -> Unit

    Parse argument list for CLI tools

    Match OptionName or LongOptionName then interpret with Spec and use Description to generate -h or --help options message.

    speclist - (LongOptionName, OptionName, Spec, Description) of Array

    rest - rest arguments handler

    usage_msg - synopsis usage

    argv - input argument list

    Source Files

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io