Sign in

    units-converter

    A small LunarUnits-powered unit conversion CLI.

    moonbit
    units
    converter
    cli
    Download zip
    Version
    0.1.0
    License
    Apache-2.0
    Last updated
    3 months ago
    Downloads
    102

    #units-converter

    English | 简体中文

    units-converter is a small MoonBit CLI powered by FrozenLemonTee/LunarUnits. It converts unit-bearing quantity expressions with the uc command.

    #Usage

    During development, run the command through moon:

    moon run cmd/main -- "9.8 m/s^2" "ft/s^2" moon run cmd/main -- "60 km/h" "m/s" moon run cmd/main -- "1 kWh" "J" moon run cmd/main -- "3 m" "s"

    Subcommands:

    moon run cmd/main -- parse "9.8 m/s^2" moon run cmd/main -- parse-unit "kg*m/s^2" moon run cmd/main -- inspect N

    Output format:

    moon run cmd/main -- --format si "9.8 m/s^2" "ft/s^2" moon run cmd/main -- --format latex "9.8 m/s^2" "ft/s^2"

    Help:

    moon run cmd/main -- --help moon run cmd/main -- parse --help

    #Why LunarUnits

    This CLI does not maintain its own unit table or conversion rules. It delegates to LunarUnits for:

    • parsing quantity and unit expressions;
    • resolving symbols through the preset catalog;
    • checking dimensional compatibility before conversion;
    • formatting quantities and units.

    That means invalid conversions such as 3 m to s are rejected by the same dimension model used by LunarUnits itself.

    #Development

    moon test moon info moon fmt

    CliResult

    pub(all) enum CliResult {
    Ok(String)
    Err(String)
    } derive(Eq,
    Debug
    )

    Result of a CLI command after argument parsing.
    impl Show for CliResult

    parse_format_style

    fn parse_format_style(style : String) ->
    FormatStyle
    ?

    Returns the unit formatter style selected by CLI text.

    run_convert

    fn run_convert(quantity_text : String, target_unit_text : String, format? : String) -> CliResult

    Converts a parsed quantity expression to a target unit expression.

    run_inspect

    fn run_inspect(symbol : String, format? : String) -> CliResult

    Looks up one unit symbol through the preset catalog.

    run_parse

    fn run_parse(input : String, format? : String) -> CliResult

    Parses a quantity expression and renders its normalized quantity.

    run_parse_unit

    fn run_parse_unit(input : String, format? : String) -> CliResult

    Parses a unit expression and renders its normalized unit.