Skip to content

Commit

Permalink
run gleam fix and update for gleam 0.33
Browse files Browse the repository at this point in the history
  • Loading branch information
TanklesXL committed Dec 28, 2023
1 parent 6cc046b commit 003c9ce
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 108 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
erlang: ["25.3.2.3", "26.0.2"]
gleam: ["0.32.4"]
gleam: ["0.33.0"]
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- uses: actions/checkout@v2
- uses: ./.github/actions/test
with:
gleam-version: "0.32.4"
gleam-version: "0.33.0"
- name: publish to hex
env:
HEXPM_USER: ${{ secrets.HEXPM_USER }}
Expand Down
2 changes: 0 additions & 2 deletions .tool-versions

This file was deleted.

5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog

## [Unreleased](https://github.com/TanklesXL/glint/compare/v0.13.0...HEAD)
## [0.14.0](https://github.com/TanklesXL/glint/compare/v0.14.0...HEAD)

- updated to work with gleam 0.33
- removed deprecated stub api

## [0.13.0](https://github.com/TanklesXL/glint/compare/v0.12.0...v0.13.0)

Expand Down
3 changes: 1 addition & 2 deletions examples/hello/.github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ jobs:
- uses: erlef/[email protected]
with:
otp-version: "25.2"
gleam-version: "0.30.3"
gleam-version: "0.33.0"
rebar3-version: "3"
# elixir-version: "1.14.2"
- run: gleam format --check src test
- run: gleam deps download
- run: gleam test
3 changes: 2 additions & 1 deletion examples/hello/gleam.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name = "hello"
version = "0.1.0"
description = "A Gleam project"
gleam = ">= 0.32.0"

# Fill out these fields if you intend to generate HTML documentation or publish
# your project to the Hex package manager.
Expand All @@ -16,4 +17,4 @@ snag = "~> 0.2"
gleam_erlang = "~> 0.19"

[dev-dependencies]
gleeunit = "~> 0.10"
gleeunit = "~> 1.0"
17 changes: 8 additions & 9 deletions examples/hello/manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@
# You typically do not need to edit this file

packages = [
{ name = "gleam_bitwise", version = "1.3.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_bitwise", source = "hex", outer_checksum = "E2A46EE42E5E9110DAD67E0F71E7358CBE54D5EC22C526DD48CBBA3223025792" },
{ name = "gleam_community_ansi", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_community_colour", "gleam_stdlib", "gleam_bitwise"], otp_app = "gleam_community_ansi", source = "hex", outer_checksum = "6E4E0CF2B207C1A7FCD3C21AA43514D67BC7004F21F82045CDCCE6C727A14862" },
{ name = "gleam_community_colour", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_bitwise", "gleam_stdlib"], otp_app = "gleam_community_colour", source = "hex", outer_checksum = "D27CE357ECB343929A8CEC3FBA0B499943A47F0EE1F589EE16AFC2DC21C61E5B" },
{ name = "gleam_erlang", version = "0.22.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "367D8B41A7A86809928ED1E7E55BFD0D46D7C4CF473440190F324AFA347109B4" },
{ name = "gleam_stdlib", version = "0.31.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "6D1BC5B4D4179B9FEE866B1E69FE180AC2CE485AD90047C0B32B2CA984052736" },
{ name = "gleeunit", version = "0.11.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "1397E5C4AC4108769EE979939AC39BF7870659C5AFB714630DEEEE16B8272AD5" },
{ name = "glint", version = "0.12.1", build_tools = ["gleam"], requirements = ["gleam_community_ansi", "gleam_community_colour", "gleam_stdlib", "snag"], source = "local", path = "../.." },
{ name = "snag", version = "0.2.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "snag", source = "hex", outer_checksum = "8FD70D8FB3728E08AC425283BB509BB0F012BE1AE218424A597CDE001B0EE589" },
{ name = "gleam_community_ansi", version = "1.3.0", build_tools = ["gleam"], requirements = ["gleam_community_colour", "gleam_stdlib"], otp_app = "gleam_community_ansi", source = "hex", outer_checksum = "AB7C3CCC894653637E02DC455D5890C8CF3064E83E78CFE61145A4C458D02DE6" },
{ name = "gleam_community_colour", version = "1.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_community_colour", source = "hex", outer_checksum = "A49A5E3AE8B637A5ACBA80ECB9B1AFE89FD3D5351FF6410A42B84F666D40D7D5" },
{ name = "gleam_erlang", version = "0.23.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "C21CFB816C114784E669FFF4BBF433535EEA9960FA2F216209B8691E87156B96" },
{ name = "gleam_stdlib", version = "0.34.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "1FB8454D2991E9B4C0C804544D8A9AD0F6184725E20D63C3155F0AEB4230B016" },
{ name = "gleeunit", version = "1.0.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "D364C87AFEB26BDB4FB8A5ABDE67D635DC9FA52D6AB68416044C35B096C6882D" },
{ name = "glint", version = "0.13.0", build_tools = ["gleam"], requirements = ["gleam_community_ansi", "gleam_community_colour", "gleam_stdlib", "snag"], source = "local", path = "../.." },
{ name = "snag", version = "0.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "snag", source = "hex", outer_checksum = "54D32E16E33655346AA3E66CBA7E191DE0A8793D2C05284E3EFB90AD2CE92BCC" },
]

[requirements]
gleam_erlang = { version = "~> 0.19" }
gleam_stdlib = { version = "~> 0.29" }
gleeunit = { version = "~> 0.10" }
gleeunit = { version = "~> 1.0" }
glint = { path = "../.." }
snag = { version = "~> 0.2" }
4 changes: 2 additions & 2 deletions gleam.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "glint"
version = "0.13.0"
version = "0.14.0"

# Fill out these fields if you intend to generate HTML documentation or publishname = "glint"
# your project to the Hex package manager.
Expand All @@ -20,4 +20,4 @@ gleam_community_ansi = "~> 1.0"
gleam_community_colour = "~> 1.0"

[dev-dependencies]
gleeunit = "~> 0.5"
gleeunit = "~> 1.0"
12 changes: 6 additions & 6 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
# You typically do not need to edit this file

packages = [
{ name = "gleam_community_ansi", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_community_colour", "gleam_stdlib"], otp_app = "gleam_community_ansi", source = "hex", outer_checksum = "8B5A9677BC5A2738712BBAF2BA289B1D8195FDF962BBC769569976AD5E9794E1" },
{ name = "gleam_community_colour", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_community_colour", source = "hex", outer_checksum = "036C206886AFB9F153C552700A7A0B4D2864E3BC96A20C77E5F34A013C051BE3" },
{ name = "gleam_stdlib", version = "0.32.1", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "ABF00CDCCB66FABBCE351A50060964C4ACE798F95A0D78622C8A7DC838792577" },
{ name = "gleeunit", version = "0.11.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "1397E5C4AC4108769EE979939AC39BF7870659C5AFB714630DEEEE16B8272AD5" },
{ name = "snag", version = "0.2.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "snag", source = "hex", outer_checksum = "8FD70D8FB3728E08AC425283BB509BB0F012BE1AE218424A597CDE001B0EE589" },
{ name = "gleam_community_ansi", version = "1.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_community_colour"], otp_app = "gleam_community_ansi", source = "hex", outer_checksum = "AB7C3CCC894653637E02DC455D5890C8CF3064E83E78CFE61145A4C458D02DE6" },
{ name = "gleam_community_colour", version = "1.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_community_colour", source = "hex", outer_checksum = "A49A5E3AE8B637A5ACBA80ECB9B1AFE89FD3D5351FF6410A42B84F666D40D7D5" },
{ name = "gleam_stdlib", version = "0.34.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "1FB8454D2991E9B4C0C804544D8A9AD0F6184725E20D63C3155F0AEB4230B016" },
{ name = "gleeunit", version = "1.0.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "D364C87AFEB26BDB4FB8A5ABDE67D635DC9FA52D6AB68416044C35B096C6882D" },
{ name = "snag", version = "0.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "snag", source = "hex", outer_checksum = "54D32E16E33655346AA3E66CBA7E191DE0A8793D2C05284E3EFB90AD2CE92BCC" },
]

[requirements]
gleam_community_ansi = { version = "~> 1.0" }
gleam_community_colour = { version = "~> 1.0" }
gleam_stdlib = { version = "~> 0.19" }
gleeunit = { version = "~> 0.5" }
gleeunit = { version = "~> 1.0" }
snag = { version = "~> 0.2" }
79 changes: 24 additions & 55 deletions src/glint.gleam
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gleam/map.{type Map}
import gleam/dict
import gleam/option.{type Option, None, Some}
import gleam/list
import gleam/io
Expand Down Expand Up @@ -93,7 +93,7 @@ pub type Runner(a) =
type CommandNode(a) {
CommandNode(
contents: Option(Command(a)),
subcommands: Map(String, CommandNode(a)),
subcommands: dict.Dict(String, CommandNode(a)),
)
}

Expand All @@ -116,7 +116,7 @@ pub type CmdResult(a) =
/// Creates a new command tree.
///
pub fn new() -> Glint(a) {
Glint(config: default_config, cmd: empty_command(), global_flags: map.new())
Glint(config: default_config, cmd: empty_command(), global_flags: dict.new())
}

/// Adds a new command to be run at the specified path.
Expand Down Expand Up @@ -154,7 +154,7 @@ fn do_add(
CommandNode(
..root,
subcommands: {
use node <- map.update(root.subcommands, x)
use node <- dict.update(root.subcommands, x)
node
|> option.lazy_unwrap(empty_command)
|> do_add(xs, contents)
Expand All @@ -166,7 +166,7 @@ fn do_add(
/// Helper for initializing empty commands
///
fn empty_command() -> CommandNode(a) {
CommandNode(contents: None, subcommands: map.new())
CommandNode(contents: None, subcommands: dict.new())
}

/// Trim each path element and remove any resulting empty strings.
Expand All @@ -180,7 +180,7 @@ fn sanitize_path(path: List(String)) -> List(String) {
/// Create a Command(a) from a Runner(a)
///
pub fn command(do runner: Runner(a)) -> Command(a) {
Command(do: runner, flags: map.new(), description: "")
Command(do: runner, flags: dict.new(), description: "")
}

/// Attach a description to a Command(a)
Expand All @@ -196,7 +196,7 @@ pub fn flag(
at key: String,
of flag: flag.FlagBuilder(_),
) -> Command(a) {
Command(..cmd, flags: map.insert(cmd.flags, key, flag.build(flag)))
Command(..cmd, flags: dict.insert(cmd.flags, key, flag.build(flag)))
}

/// Add a `flag.Flag to a `Command` when the flag name and builder are bundled as a #(String, flag.FlagBuilder(a)).
Expand All @@ -216,7 +216,7 @@ pub fn flag_tuple(
///
pub fn flags(cmd: Command(a), with flags: List(#(String, Flag))) -> Command(a) {
use cmd, #(key, flag) <- list.fold(flags, cmd)
Command(..cmd, flags: map.insert(cmd.flags, key, flag))
Command(..cmd, flags: dict.insert(cmd.flags, key, flag))
}

/// Add global flags to the existing command tree
Expand All @@ -228,7 +228,7 @@ pub fn global_flag(
) -> Glint(a) {
Glint(
..glint,
global_flags: map.insert(glint.global_flags, key, flag.build(flag)),
global_flags: dict.insert(glint.global_flags, key, flag.build(flag)),
)
}

Expand All @@ -251,11 +251,8 @@ pub fn global_flags(glint: Glint(a), flags: List(#(String, Flag))) -> Glint(a) {
Glint(
..glint,
global_flags: {
list.fold(
flags,
glint.global_flags,
fn(acc, tup) { map.insert(acc, tup.0, tup.1) },
)
use acc, elem <- list.fold(flags, glint.global_flags)
dict.insert(acc, elem.0, elem.1)
},
)
}
Expand Down Expand Up @@ -318,15 +315,10 @@ fn do_execute(
case map.get(cmd.subcommands, arg) {
// subcommand found, continue
Ok(cmd) ->
do_execute(
cmd,
config,
global_flags,
rest,
flags,
help,
[arg, ..command_path],
)
do_execute(cmd, config, global_flags, rest, flags, help, [
arg,
..command_path
])
// subcommand not found, but help flag has been passed
// generate and return help message
_ if help ->
Expand Down Expand Up @@ -470,7 +462,8 @@ fn usage_help(cmd_name: String, flags: FlagMap, config: Config) -> String {
|> sb.prepend(
config.pretty_help
|> option.map(fn(styling) { heading_style(usage_heading, styling.usage) })
|> option.unwrap(usage_heading) <> "\n\t",
|> option.unwrap(usage_heading)
<> "\n\t",
)
|> sb.to_string
}
Expand All @@ -497,7 +490,9 @@ fn cmd_help(
let flags_help_body =
config.pretty_help
|> option.map(fn(p) { heading_style(flags_heading, p.flags) })
|> option.unwrap(flags_heading) <> "\n\t" <> string.join(
|> option.unwrap(flags_heading)
<> "\n\t"
<> string.join(
list.sort([help_flag_message, ..flag.flags_help(flags)], string.compare),
"\n\t",
)
Expand All @@ -521,7 +516,9 @@ fn cmd_help(
subcommands_help_body ->
config.pretty_help
|> option.map(fn(p) { heading_style(subcommands_heading, p.subcommands) })
|> option.unwrap(subcommands_heading) <> "\n\t" <> subcommands_help_body
|> option.unwrap(subcommands_heading)
<> "\n\t"
<> subcommands_help_body
}

// join the resulting help blocks into the final help message
Expand All @@ -531,7 +528,7 @@ fn cmd_help(
}

// create the help text for subcommands
fn subcommands_help(cmds: Map(String, CommandNode(a))) -> String {
fn subcommands_help(cmds: dict.Dict(String, CommandNode(a))) -> String {
cmds
|> map.map_values(subcommand_help)
|> map.values
Expand All @@ -558,31 +555,3 @@ fn heading_style(heading: String, colour: Colour) -> String {
|> ansi.hex(colour.to_rgb_hex(colour))
|> ansi.reset
}

// -- DEPRECATED: STUBS --

/// DEPRECATED: use `glint.cmd` and related new functions instead to create a Command
///
/// Create command stubs to be used in `add_command_from_stub`
///
pub type Stub(a) {
Stub(
path: List(String),
run: Runner(a),
flags: List(#(String, Flag)),
description: String,
)
}

/// Add a command to the root given a stub
///
@deprecated("use `glint.cmd` and related new functions instead to create a Command")
pub fn add_command_from_stub(to glint: Glint(a), with stub: Stub(a)) -> Glint(a) {
add(
to: glint,
at: stub.path,
do: command(stub.run)
|> flags(stub.flags)
|> description(stub.description),
)
}
20 changes: 10 additions & 10 deletions src/glint/flag.gleam
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gleam/map
import gleam/dict
import gleam/string
import gleam/result
import gleam/int
Expand Down Expand Up @@ -209,12 +209,12 @@ pub fn default(for builder: FlagBuilder(a), of default: a) -> FlagBuilder(a) {
/// Associate flag names to their current values.
///
pub type Map =
map.Map(String, Flag)
dict.Dict(String, Flag)

/// Convert a list of flags to a Map.
///
pub fn build_map(flags: List(#(String, Flag))) -> Map {
map.from_list(flags)
dict.from_list(flags)
}

/// Updates a flag value, ensuring that the new value can satisfy the required type.
Expand All @@ -237,7 +237,7 @@ fn update_flag_value(in flags: Map, with data: #(String, String)) -> Result(Map)
compute_flag(with: input, given: contents.value)
|> result.map_error(layer_invalid_flag(_, key)),
)
map.insert(flags, key, Flag(..contents, value: value))
dict.insert(flags, key, Flag(..contents, value: value))
}

fn attempt_toggle_flag(in flags: Map, at key: String) -> Result(Map) {
Expand All @@ -247,14 +247,14 @@ fn attempt_toggle_flag(in flags: Map, at key: String) -> Result(Map) {
Internal(..internal, value: Some(True))
|> B
|> fn(val) { Flag(..contents, value: val) }
|> map.insert(into: flags, for: key)
|> Ok()
|> dict.insert(into: flags, for: key)
|> Ok
B(Internal(Some(val), ..) as internal) ->
Internal(..internal, value: Some(!val))
|> B
|> fn(val) { Flag(..contents, value: val) }
|> map.insert(into: flags, for: key)
|> Ok()
|> dict.insert(into: flags, for: key)
|> Ok
_ -> Error(no_value_flag_err(key))
}
}
Expand Down Expand Up @@ -342,7 +342,7 @@ fn flag_help(flag: #(String, Flag)) -> String {
///
pub fn flags_help(flags: Map) -> List(String) {
flags
|> map.to_list
|> dict.to_list
|> list.map(flag_help)
}

Expand All @@ -351,7 +351,7 @@ pub fn flags_help(flags: Map) -> List(String) {
/// Access the contents for the associated flag
///
fn access(flags: Map, name: String) -> Result(Flag) {
map.get(flags, name)
dict.get(flags, name)
|> result.replace_error(undefined_flag_err(name))
}

Expand Down
Loading

0 comments on commit 003c9ce

Please sign in to comment.