Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shared typed parameters for named arguments and flags #63

Draft
wants to merge 7 commits into
base: next
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
uses: TanklesXL/gleam_actions/.github/workflows/release.yaml@main
secrets: inherit
with:
gleam_version: 1.4.1
gleam_version: 1.5.1
erlang_version: 27
test_erlang: true
test_node: true
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ jobs:
test:
uses: TanklesXL/gleam_actions/.github/workflows/test.yaml@main
with:
gleam_version: 1.4.1
gleam_version: 1.5.1
test_node: true
test_erlang: true
2 changes: 0 additions & 2 deletions .mise.toml

This file was deleted.

38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ import argv
fn caps_flag() -> glint.Flag(Bool) {
// create a new boolean flag with key "caps"
// this flag will be called as --caps=true (or simply --caps as glint handles boolean flags in a bit of a special manner) from the command line
glint.bool_flag("caps")
glint.default("caps")
// set the flag default value to False
|> glint.flag_default(False)
|> glint.default(False)
// set the flag help text
|> glint.flag_help("Capitalize the hello message")
|> glint.param_help("Capitalize the hello message")
}

/// the glint command that will be executed
Expand Down Expand Up @@ -120,16 +120,16 @@ Glint flags are a type-safe way to provide options to your commands.

- Create a new flag with a typed flag constructor function:

- `glint.int_flag`: `glint.Flag(Int)`
- `glint.ints_flag`: `glint.Flag(List(Int))`
- `glint.float_flag`: `glint.Flag(Float)`
- `glint.floats_flag`: `glint.Flag(List(Floats))`
- `glint.string_flag`: `glint.Flag(String)`
- `glint.strings_flag`: `glint.Flag(List(String))`
- `glint.bool_flag`: `glint.Flag(Bool)`
- `glint.int`: `glint.Flag(Int)`
- `glint.ints`: `glint.Flag(List(Int))`
- `glint.float`: `glint.Flag(Float)`
- `glint.floats`: `glint.Flag(List(Floats))`
- `glint.string`: `glint.Flag(String)`
- `glint.strings`: `glint.Flag(List(String))`
- `glint.default`: `glint.Flag(Bool)`

- Set the flag description with `glint.flag_help`
- Set the flag default value with `glint.flag_default`, **note**: it is safe to use `let assert` when fetching values for flags with default values.
- Set the flag description with `glint.param_help`
- Set the flag default value with `glint.default`, **note**: it is safe to use `let assert` when fetching values for flags with default values.
- Add a flag to a command with `glint.flag`.
- Add a `constraint.Constraint(a)` to a `glint.Flag(a)` with `glint.flag_constraint`

Expand All @@ -148,8 +148,8 @@ import glint
import snag
// ...
// with pipes
glint.int_flag("my_int")
|> glint.flag_default(0)
glint.int("my_int")
|> glint.default(0)
|> glint.constraint(fn(i){
case i < 0 {
True -> snag.error("cannot be negative")
Expand All @@ -159,8 +159,8 @@ glint.int_flag("my_int")
// or
// with use
use i <- glint.flag_constraint(
glint.int_flag("my_int")
|> glint.flag_default(0)
glint.int("my_int")
|> glint.default(0)
)
case i < 0 {
True -> snag.error("cannot be negative")
Expand All @@ -181,8 +181,8 @@ import glint
import glint/constraint
import snag
// ...
glint.ints_flag("my_ints")
|> glint.flag_default([])
glint.ints("my_ints")
|> glint.default([])
|> glint.flag_constraint(
[1, 2, 3, 4]
|> constraint.one_of
Expand All @@ -208,7 +208,7 @@ Help text descriptions can be attached to all of glint's components:

- attach global help text with `glint.global_help`
- attach comand help text with `glint.command_help`
- attach flag help text with `glint.flag_help`
- attach flag help text with `glint.param_help`
- attach help text to a non-initialized command with `glint.path_help`

#### Help text formatting
Expand Down
19 changes: 9 additions & 10 deletions birdie_snapshots/cmd1_help.accepted
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
version: 1.1.5
version: 1.1.8
title: cmd1 help
file: ./test/glint_test.gleam
test_name: cmd1_help_test
Expand All @@ -11,8 +11,13 @@ Command: cmd1
This is cmd1

USAGE:
gleam run -m test cmd1 ( cmd3 | cmd4 ) [ ARGS ] [ --flag2=<INT>
--global=<STRING> --very-very-very-long-flag=<FLOAT_LIST> ]
gleam run -m test cmd1 ( cmd3 | cmd4 ) [ ARGS ] [ FLAGS ]

SUBCOMMANDS:
cmd3 This is cmd3

cmd4 This is cmd4 which has a very very very very very very
very very long description

FLAGS:
--flag2=<INT> This is flag2
Expand All @@ -23,10 +28,4 @@ FLAGS:

--very-very-very-long-flag=<FLOAT_LIST> This is a very long flag with a
very very very very very very long
description

SUBCOMMANDS:
cmd3 This is cmd3

cmd4 This is cmd4 which has a very very very very very very
very very long description
description
6 changes: 3 additions & 3 deletions birdie_snapshots/cmd2_help.accepted
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
version: 1.1.5
version: 1.1.8
title: cmd2 help
file: ./test/glint_test.gleam
test_name: help_test
test_name: cmd2_help_test
---
Some awesome global help text!

Expand All @@ -11,7 +11,7 @@ Command: cmd2
This is cmd2

USAGE:
gleam run -m test cmd2 <arg1> <arg2> [ --global=<STRING> ]
gleam run -m test cmd2 <arg1> <arg2> [ FLAGS ]

FLAGS:
--global=<STRING> This is a global flag
Expand Down
7 changes: 3 additions & 4 deletions birdie_snapshots/cmd3_help.accepted
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
version: 1.1.5
version: 1.1.8
title: cmd3 help
file: ./test/glint_test.gleam
test_name: help_test
test_name: cmd3_help_test
---
Some awesome global help text!

Expand All @@ -11,8 +11,7 @@ Command: cmd1 cmd3
This is cmd3

USAGE:
gleam run -m test cmd1 cmd3 <woo> [ 2 or more arguments ] [ --flag3=<BOOL>
--global=<STRING> ]
gleam run -m test cmd1 cmd3 <woo> [ 2 or more arguments ] [ FLAGS ]

FLAGS:
--flag3=<BOOL> This is flag3
Expand Down
6 changes: 3 additions & 3 deletions birdie_snapshots/cmd4_help.accepted
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
version: 1.1.5
version: 1.1.8
title: cmd4 help
file: ./test/glint_test.gleam
test_name: help_test
test_name: cmd4_help_test
---
Some awesome global help text!

Expand All @@ -12,7 +12,7 @@ This is cmd4 which has a very very very very very very very very long
description

USAGE:
gleam run -m test cmd1 cmd4 [ --flag4=<FLOAT> --global=<STRING> ]
gleam run -m test cmd1 cmd4 [ FLAGS ]

FLAGS:
--flag4=<FLOAT> This is flag4
Expand Down
14 changes: 7 additions & 7 deletions birdie_snapshots/cmd6_help.accepted
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
version: 1.1.5
version: 1.1.8
title: cmd6 help
file: ./test/glint_test.gleam
test_name: help_test
test_name: cmd6_help_test
---
Some awesome global help text!

Expand All @@ -11,11 +11,11 @@ Command: cmd5 cmd6
This is cmd6

USAGE:
gleam run -m test cmd5 cmd6 ( cmd7 ) [ ARGS ] [ --global=<STRING> ]
gleam run -m test cmd5 cmd6 ( cmd7 ) [ ARGS ] [ FLAGS ]

SUBCOMMANDS:
cmd7 This is cmd7

FLAGS:
--global=<STRING> This is a global flag
--help Print help information

SUBCOMMANDS:
cmd7 This is cmd7
--help Print help information
10 changes: 5 additions & 5 deletions birdie_snapshots/cmd6_help_with_residual_args.accepted
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ Command: cmd5 cmd6
This is cmd6

USAGE:
gleam run -m test cmd5 cmd6 ( cmd7 ) [ ARGS ] [ --global=<STRING> ]
gleam run -m test cmd5 cmd6 ( cmd7 ) [ ARGS ] [ FLAGS ]

SUBCOMMANDS:
cmd7 This is cmd7

FLAGS:
--global=<STRING> This is a global flag
--help Print help information

SUBCOMMANDS:
cmd7 This is cmd7
--help Print help information
16 changes: 8 additions & 8 deletions birdie_snapshots/root_help.accepted
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
version: 1.1.5
version: 1.1.8
title: root help
file: ./test/glint_test.gleam
test_name: root_help_test
Expand All @@ -10,12 +10,7 @@ This is the root command

USAGE:
gleam run -m test ( cmd1 | cmd2 | cmd5 | cmd8-very-very-very-very-long )
<arg1> <arg2> [ ARGS ] [ --flag1=<STRING> --global=<STRING> ]

FLAGS:
--flag1=<STRING> This is flag1
--global=<STRING> This is a global flag
--help Print help information
<arg1> <arg2> [ ARGS ] [ FLAGS ]

SUBCOMMANDS:
cmd1 This is cmd1
Expand All @@ -32,4 +27,9 @@ SUBCOMMANDS:
New new line


New new new line.
New new new line.

FLAGS:
--flag1=<STRING> This is flag1
--global=<STRING> This is a global flag
--help Print help information
1 change: 1 addition & 0 deletions gleam.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ gleam_stdlib = "~> 0.39 or ~> 1.0"
snag = "~> 0.3"
gleam_community_ansi = "~> 1.0"
gleam_community_colour = "~> 1.0"
lenient_parse = ">= 1.0.1 and < 2.0.0"

[dev-dependencies]
gleeunit = "~> 1.0"
Expand Down
2 changes: 2 additions & 0 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ packages = [
{ name = "gleeunit", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "F7A7228925D3EE7D0813C922E062BFD6D7E9310F0BEE585D3A42F3307E3CFD13" },
{ name = "glexer", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "glexer", source = "hex", outer_checksum = "BD477AD657C2B637FEF75F2405FAEFFA533F277A74EF1A5E17B55B1178C228FB" },
{ name = "justin", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "justin", source = "hex", outer_checksum = "7FA0C6DB78640C6DC5FBFD59BF3456009F3F8B485BF6825E97E1EB44E9A1E2CD" },
{ name = "lenient_parse", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "lenient_parse", source = "hex", outer_checksum = "6C7A87C03C81260FA443607AFFBE4629076AED5077C23E7AC57C5F1FDEB14732" },
{ name = "rank", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "rank", source = "hex", outer_checksum = "5660E361F0E49CBB714CC57CC4C89C63415D8986F05B2DA0C719D5642FAD91C9" },
{ name = "simplifile", version = "2.0.1", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "5FFEBD0CAB39BDD343C3E1CCA6438B2848847DC170BA2386DF9D7064F34DF000" },
{ name = "snag", version = "0.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "snag", source = "hex", outer_checksum = "54D32E16E33655346AA3E66CBA7E191DE0A8793D2C05284E3EFB90AD2CE92BCC" },
Expand All @@ -28,4 +29,5 @@ gleam_community_ansi = { version = "~> 1.0" }
gleam_community_colour = { version = "~> 1.0" }
gleam_stdlib = { version = "~> 0.39 or ~> 1.0" }
gleeunit = { version = "~> 1.0" }
lenient_parse = { version = ">= 1.0.1 and < 2.0.0" }
snag = { version = "~> 0.3" }
Loading
Loading