glint

Hex Package Hex.pm Hex Docs GitHub Workflow Status

Gleam command line argument parsing with basic flag support.

Installation

To install from hex:

gleam add glint

Usage

You can import glint as a dependency and use it as follows: (found in examples/hello/src/hello.gleam directory)

import gleam/io
import gleam/map
import gleam/string.{join, uppercase}
import gleam/erlang.{start_arguments}
import glint.{CommandInput}
import glint/flag

pub fn main() {
  let hello = fn(input: CommandInput) {
    assert Ok(flag.B(caps)) = map.get(input.flags, "caps")
    let to_say = ["Hello,", ..input.args]
    case caps {
      True ->
        to_say
        |> join(" ")
        |> uppercase()

      False -> join(to_say, " ")
    }
    |> string.append("!")
    |> io.println()
  }

  glint.new()
  |> glint.add_command([], hello, [flag.bool("caps", False)])
  |> glint.run(start_arguments())
}

Run it with either of:

Note: Due to this issue commands with flags immediately after gleam run must include the -- as shown above