1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# glint
[](https://hex.pm/packages/glint)
[](https://hex.pm/packages/glint)
[](https://hexdocs.pm/glint/)
[](https://github.com/tanklesxl/glint/actions)
Gleam command line argument parsing with basic flag support.
## Installation
To install from hex:
```sh
gleam add glint
```
## Usage
### Glint's Core
`glint` is conceptually quite small, your general flow will be:
1. create a new glint instance with `glint.new`
1. configure it with `glint.with_pretty_help` and other configuration functions
1. add commands with `glint.add`
1. create a new command with `glint.cmd`
1. assign that command any flags required
1. assign the command a custom description
1. run your cli with `glnt.run`, run with a function to handle command output with `glint.run_and_handle`
### Mini Example
You can import `glint` as a dependency and use it to build simple command-line applications like the following simplified version of the [the hello world example](https://github.com/TanklesXL/glint/tree/main/examples/hello/README.md)
```gleam
// stdlib imports
import gleam/io
import gleam/list
import gleam/result
import gleam/string.{uppercase}
// external dep imports
import snag
// glint imports
import glint
import glint/flag
// erlang-specific imports
@target(erlang)
import gleam/erlang.{start_arguments}
/// the key for the caps flag
const caps = "caps"
/// a boolean flag with default False to control message capitalization.
///
fn caps_flag() -> flag.FlagBuilder(Bool) {
flag.bool()
|> flag.default(False)
|> flag.description("Capitalize the provided name")
}
/// the command function that will be executed
///
fn hello(input: glint.CommandInput) -> Nil {
let assert Ok(caps) = flag.get_bool(from: input.flags, for: caps)
let name =
case input.args {
[] -> "Joe"
[name,..] -> name
}
let msg = "Hello, " <> name <> "!"
case caps {
True -> uppercase(msg)
False -> msg
}
|> io.println
}
pub fn main() {
// create a new glint instance
glint.new()
// with an app name of "hello", this is used when printing help text
|> glint.with_name("hello")
// with pretty help enabled, using the built-in colours
|> glint.with_pretty_help(glint.default_pretty_help())
// with a root command that executes the `hello` function
|> glint.add(
// add the command to the root
at: [],
// create the command, add any flags
do: glint.command(hello)
// with flag `caps`
|> glint.flag(caps, caps_flag())
// with a short description
|> glint.description("Prints Hello, <NAME>!"),
)
|> glint.run(start_arguments())
}
```
|