Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
TanklesXL committed Mar 13, 2024
1 parent 4239c97 commit 6c51d74
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 34 deletions.
35 changes: 11 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,31 +53,26 @@ import argv
import glint
import glint/flag
/// the key for the caps flag
const caps = "caps"
/// a boolean flag with default False to control message capitalization.
///
// this function returns the builder for the caps flag
fn caps_flag() -> flag.Builder(Bool) {
flag.bool()
|> flag.default(False)
|> flag.description("Capitalize the provided name")
}
/// the command function that will be executed
/// the glint command 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 {
fn hello() -> glint.Command(Nil) {
use <- glint.description("Prints Hello, <NAME>!")
use caps <- glint.flag("caps",caps_flag())
use _, args, flags <- glint.command()
let assert Ok(caps) = caps(flags)
let name = case args {
[] -> "Joe"
[name,..] -> name
}
}
let msg = "Hello, " <> name <> "!"
case caps {
True -> uppercase(msg)
False -> msg
Expand All @@ -93,16 +88,8 @@ pub fn main() {
// 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.add(at: [], do: hello)
// execute given arguments from stdin
|> glint.run(argv.load().arguments)
}
```
20 changes: 10 additions & 10 deletions src/glint.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -484,12 +484,12 @@ fn execute_root(
False ->
snag.error(
"unmatched named arguments: "
<> {
contents.named_args
|> list.drop(list.length(named))
|> list.map(fn(s) { "'" <> s <> "'" })
|> string.join(", ")
},
<> {
contents.named_args
|> list.drop(list.length(named))
|> list.map(fn(s) { "'" <> s <> "'" })
|> string.join(", ")
},
)
}
})
Expand All @@ -515,8 +515,8 @@ fn execute_root(
Error(#(snag, help)) ->
Error(
snag.pretty_print(snag)
<> "\nSee the following help text, available via the '--help' flag.\n\n"
<> help,
<> "\nSee the following help text, available via the '--help' flag.\n\n"
<> help,
)
}
}
Expand Down Expand Up @@ -708,8 +708,8 @@ fn build_subcommands_help(
Metadata(
name: name,
description: cmd.contents
|> option.map(fn(command) { command.description })
|> option.unwrap(""),
|> option.map(fn(command) { command.description })
|> option.unwrap(""),
),
..acc
]
Expand Down

0 comments on commit 6c51d74

Please sign in to comment.