From 422f6765197d0b85affbaefc1265ee733a583b23 Mon Sep 17 00:00:00 2001 From: tynanbe Date: Fri, 16 Feb 2024 16:54:15 -0600 Subject: [PATCH] Support gleam_stdlib v1.0 --- .github/workflows/ci.yml | 4 +- CHANGELOG.md | 6 + gleam.toml | 18 +-- manifest.toml | 28 ++-- src/rad.gleam | 26 ++-- src/rad/task.gleam | 29 ++-- src/rad/toml.gleam | 5 +- src/rad/util.gleam | 20 +-- src/rad/workbook.gleam | 32 ++-- src/rad/workbook/standard.gleam | 204 ++++++++++++-------------- test/rad/task_test.gleam | 38 ++--- test/rad/util_test.gleam | 32 ++-- test/rad/workbook/standard_test.gleam | 16 +- test/rad/workbook_test.gleam | 12 +- test/rad_test.gleam | 46 +++--- 15 files changed, 260 insertions(+), 256 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 81a4bd9..7f39ba6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,9 +15,9 @@ jobs: - uses: erlef/setup-beam@v1 with: - otp-version: "25" + otp-version: "26" rebar3-version: "3" - gleam-version: "0.33" + gleam-version: "1.0.0-rc2" - uses: denoland/setup-deno@v1 with: diff --git a/CHANGELOG.md b/CHANGELOG.md index 22e6817..b4a96a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +- Rad now supports `gleam_stdlib` v1.0. +- Rad now requires Gleam v0.34 or later. +- Rad now requires `glint` v0.15 or later. + ## v1.0.0 - 2023-12-21 - Rad now requires Gleam v0.33 or later. diff --git a/gleam.toml b/gleam.toml index 93637af..63653b0 100644 --- a/gleam.toml +++ b/gleam.toml @@ -1,9 +1,9 @@ name = "rad" -version = "1.0.0" +version = "1.1.0-dev" description = "A task runner for Gleam projects" licences = ["Apache-2.0"] target = "javascript" -gleam = ">= 0.33.0" +gleam = ">= 0.34.0" [repository] repo = "rad" @@ -16,13 +16,13 @@ title = "Website" [dependencies] gleam_http = "~> 3.5" -gleam_json = "~> 0.7" -gleam_stdlib = "~> 0.34" -glint = "~> 0.13" -shellout = "~> 1.5" -snag = "~> 0.3" -thoas = "~> 0.4" -tomerl = "~> 0.5" +gleam_json = "~> 0.7 or ~> 1.0" +gleam_stdlib = "~> 0.34 or ~> 1.0" +glint = "~> 0.15 or ~> 1.0" +shellout = "~> 1.6" +snag = "~> 0.3 or ~> 1.0" +thoas = "~> 0.4 or ~> 1.0" +tomerl = "~> 0.5 or ~> 1.0" [dev-dependencies] gleeunit = "~> 1.0" diff --git a/manifest.toml b/manifest.toml index 930f04d..a4763e2 100644 --- a/manifest.toml +++ b/manifest.toml @@ -2,14 +2,14 @@ # You typically do not need to edit this file packages = [ - { name = "gleam_community_ansi", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_community_colour"], 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_http", version = "3.5.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_http", source = "hex", outer_checksum = "AECDA43AFD523D07A8F09068598A6E271C505278A0CB6F9C7A2E4365EAE8D11E" }, - { name = "gleam_json", version = "0.7.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "thoas"], otp_app = "gleam_json", source = "hex", outer_checksum = "CB405BD93A8828BCD870463DE29375E7B2D252D9D124C109E5B618AAC00B86FC" }, - { name = "gleam_stdlib", version = "0.34.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "1FB8454D2991E9B4C0C804544D8A9AD0F6184725E20D63C3155F0AEB4230B016" }, + { name = "gleam_community_ansi", version = "1.4.0", build_tools = ["gleam"], requirements = ["gleam_community_colour", "gleam_stdlib"], otp_app = "gleam_community_ansi", source = "hex", outer_checksum = "FE79E08BF97009729259B6357EC058315B6FBB916FAD1C2FF9355115FEB0D3A4" }, + { 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_http", version = "3.5.3", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_http", source = "hex", outer_checksum = "C2FC3322203B16F897C1818D9810F5DEFCE347F0751F3B44421E1261277A7373" }, + { name = "gleam_json", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "thoas"], otp_app = "gleam_json", source = "hex", outer_checksum = "8B197DD5D578EA6AC2C0D4BDC634C71A5BCA8E7DB5F47091C263ECB411A60DF3" }, + { name = "gleam_stdlib", version = "0.35.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "81E91937710732ED1CA1F8E83D7AD19B4E87F63A1FC644A539264B6A118003D4" }, { 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_colour", "gleam_community_ansi", "gleam_stdlib", "snag"], otp_app = "glint", source = "hex", outer_checksum = "46E56049CD370D61F720D319D0AB970408C9336EEB918F08B5DCB1DCE9845FA3" }, - { name = "shellout", version = "1.5.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "shellout", source = "hex", outer_checksum = "7B5DE499DBB3DDC25051FC1BB3770DD5466938B6A2AFA91A6FB4A4D49F4CB0D4" }, + { name = "glint", version = "0.15.0", build_tools = ["gleam"], requirements = ["gleam_community_ansi", "gleam_community_colour", "gleam_stdlib", "snag"], otp_app = "glint", source = "hex", outer_checksum = "D5324DBE11F57BF0B303D99EA086D66B8DC319EE59C1355C76EBB1544187C237" }, + { name = "shellout", version = "1.6.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "shellout", source = "hex", outer_checksum = "E2FCD18957F0E9F67E1F497FC9FF57393392F8A9BAEAEA4779541DE7A68DD7E0" }, { name = "snag", version = "0.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "snag", source = "hex", outer_checksum = "54D32E16E33655346AA3E66CBA7E191DE0A8793D2C05284E3EFB90AD2CE92BCC" }, { name = "thoas", version = "0.4.1", build_tools = ["rebar3"], requirements = [], otp_app = "thoas", source = "hex", outer_checksum = "4918D50026C073C4AB1388437132C77A6F6F7C8AC43C60C13758CC0ADCE2134E" }, { name = "tomerl", version = "0.5.0", build_tools = ["rebar3"], requirements = [], otp_app = "tomerl", source = "hex", outer_checksum = "2A7FB62F9EBF0E75561B39255638BC2B805B437C86FEC538657E7C3B576979FA" }, @@ -17,11 +17,11 @@ packages = [ [requirements] gleam_http = { version = "~> 3.5" } -gleam_json = { version = "~> 0.7" } -gleam_stdlib = { version = "~> 0.34" } +gleam_json = { version = "~> 0.7 or ~> 1.0" } +gleam_stdlib = { version = "~> 0.34 or ~> 1.0" } gleeunit = { version = "~> 1.0" } -glint = { version = "~> 0.13" } -shellout = { version = "~> 1.5" } -snag = { version = "~> 0.3" } -thoas = { version = "~> 0.4" } -tomerl = { version = "~> 0.5" } +glint = { version = "~> 0.15 or ~> 1.0" } +shellout = { version = "~> 1.6" } +snag = { version = "~> 0.3 or ~> 1.0" } +thoas = { version = "~> 0.4 or ~> 1.0" } +tomerl = { version = "~> 0.5 or ~> 1.0" } diff --git a/src/rad.gleam b/src/rad.gleam index 3de3e9b..e252217 100644 --- a/src/rad.gleam +++ b/src/rad.gleam @@ -40,16 +40,16 @@ pub fn main() -> Nil { |> glint.add( at: [], do: fn(input: CommandInput) { - "with" - |> flag.get_string(from: input.flags) - |> result.unwrap(or: with) - } - |> glint.command - |> glint.flag( - at: "with", - of: flag.string() - |> flag.default(of: with), - ), + "with" + |> flag.get_string(from: input.flags) + |> result.unwrap(or: with) + } + |> glint.command + |> glint.flag( + at: "with", + of: flag.string() + |> flag.default(of: with), + ), ) |> glint.execute(arguments(Global)) @@ -96,9 +96,9 @@ pub fn do_main(workbook: Workbook) -> Nil { |> glint.add( at: path, do: task.run(_, task) - |> glint.command - |> glint.flags(with: task.flags) - |> glint.description(task.shortdoc), + |> glint.command + |> glint.flags(with: task.flags) + |> glint.description(task.shortdoc), ) }) |> glint.execute(arguments(Normal)) diff --git a/src/rad/task.gleam b/src/rad/task.gleam index 7353107..e741628 100644 --- a/src/rad/task.gleam +++ b/src/rad/task.gleam @@ -8,6 +8,7 @@ import gleam import gleam/bool +import gleam/dict import gleam/dynamic import gleam/int import gleam/json @@ -169,9 +170,9 @@ pub fn flag( let flag = #( name, flag_fun() - |> flag.default(of: value) - |> flag.description(of: description) - |> flag.build, + |> flag.default(of: value) + |> flag.description(of: description) + |> flag.build, ) let flags = task.flags @@ -322,6 +323,8 @@ pub fn or( } } + let named_args = dict.new() + let mapper = fn(input: CommandInput, task, index, item) { case cond(input) { Each(map: mapper, ..) -> mapper(input, task, index, item) @@ -330,7 +333,7 @@ pub fn or( item |> json.decode(using: dynamic.list(of: dynamic.string)) |> result.unwrap(or: []) - |> CommandInput(flags: input.flags) + |> CommandInput(flags: input.flags, named_args: named_args) } } } @@ -384,8 +387,10 @@ pub type Formatter { pub fn formatters() -> Iterable(a) { let formatters = [ "gleam" - |> Formatter(check: ["gleam", "format", "--check"], run: ["gleam", "format"]) - |> Ok, + |> Formatter(check: ["gleam", "format", "--check"], run: [ + "gleam", "format", + ]) + |> Ok, ..formatters_from_config() ] @@ -394,6 +399,8 @@ pub fn formatters() -> Iterable(a) { |> list.map(with: fn(_result) { "" }) } + let named_args = dict.new() + let mapper = fn(input: CommandInput, _task, index, _argument) { let io_println = util.quiet_or_println(input) let check = @@ -414,7 +421,7 @@ pub fn formatters() -> Iterable(a) { let _print = [ action - |> shellout.style(with: shellout.color(["magenta"]), custom: []), + |> shellout.style(with: shellout.color(["magenta"]), custom: []), " ", formatter.name, extra, @@ -423,13 +430,13 @@ pub fn formatters() -> Iterable(a) { |> string.concat |> io_println args - |> CommandInput(flags: input.flags) + |> CommandInput(flags: input.flags, named_args: named_args) } _else -> "--fail" |> flag.update_flags(in: input.flags) |> result.unwrap(or: input.flags) - |> CommandInput(args: []) + |> CommandInput(args: [], named_args: named_args) } } @@ -520,7 +527,7 @@ pub fn targets() -> Iterable(a) { let _heading = [ " Targeting" - |> shellout.style(with: shellout.color(["magenta"]), custom: []), + |> shellout.style(with: shellout.color(["magenta"]), custom: []), " ", target, "...", @@ -672,7 +679,7 @@ pub fn trainer(runner: Runner(Result)) -> Runner(Result) { |> int.to_string [ errors - |> int.to_string, + |> int.to_string, "of", results, "task runs failed", diff --git a/src/rad/toml.gleam b/src/rad/toml.gleam index ad5681b..2b888a4 100644 --- a/src/rad/toml.gleam +++ b/src/rad/toml.gleam @@ -73,7 +73,10 @@ fn do_decode_every( |> decode( from: toml, expect: dynamic.from - |> function.compose(dynamic.dict(of: dynamic.string, to: dynamic.dynamic)), + |> function.compose(dynamic.dict( + of: dynamic.string, + to: dynamic.dynamic, + )), ), ) diff --git a/src/rad/util.gleam b/src/rad/util.gleam index 0958328..8935853 100644 --- a/src/rad/util.gleam +++ b/src/rad/util.gleam @@ -323,11 +323,11 @@ pub fn snag_pretty_print(snag: Snag) -> String { let builder = [ "error" - |> bold(and: ["red"]), + |> bold(and: ["red"]), ": " - |> bold([]), + |> bold([]), snag.issue - |> bold([]), + |> bold([]), "\n", ] |> string_builder.from_strings @@ -338,9 +338,9 @@ pub fn snag_pretty_print(snag: Snag) -> String { [ "\n", "cause" - |> bold(and: ["red"]), + |> bold(and: ["red"]), ":\n" - |> bold([]), + |> bold([]), ] |> string_builder.from_strings |> string_builder.append_builder(to: builder) @@ -355,12 +355,12 @@ fn pretty_print_cause(cause) { [ " ", index - |> int.to_string - |> bold(and: ["red"]), + |> int.to_string + |> bold(and: ["red"]), ": " - |> bold([]), + |> bold([]), line - |> bold([]), + |> bold([]), "\n", ] |> string.concat @@ -372,7 +372,7 @@ fn bold(string, and colors: List(String)) -> String { string |> shellout.style( with: shellout.display(["bold"]) - |> dict.merge(from: shellout.color(colors)), + |> dict.merge(from: shellout.color(colors)), custom: lookups, ) } diff --git a/src/rad/workbook.gleam b/src/rad/workbook.gleam index 63ab2b9..1359dd9 100644 --- a/src/rad/workbook.gleam +++ b/src/rad/workbook.gleam @@ -167,16 +167,16 @@ pub fn help(from workbook_fun: fn() -> Workbook) -> Runner(Result) { #( "help", flag.bool() - |> flag.default(of: False) - |> flag.description(of: "Print help information") - |> flag.build, + |> flag.default(of: False) + |> flag.description(of: "Print help information") + |> flag.build, ), #( "with", flag.string() - |> flag.default(of: "") - |> flag.description(of: "Specify a rad runtime") - |> flag.build, + |> flag.default(of: "") + |> flag.description(of: "Specify a rad runtime") + |> flag.build, ), ..task.flags |> list.filter(keeping: fn(flag) { @@ -211,7 +211,7 @@ pub fn help(from workbook_fun: fn() -> Workbook) -> Runner(Result) { |> string.join(with: " ") |> shellout.style( with: shellout.display(["bold"]) - |> dict.merge(from: shellout.color([path_color])), + |> dict.merge(from: shellout.color([path_color])), custom: util.lookups, ) |> Some @@ -256,7 +256,7 @@ pub fn help(from workbook_fun: fn() -> Workbook) -> Runner(Result) { "rad" |> shellout.style( with: shellout.display(["bold"]) - |> dict.merge(from: shellout.color(["pink"])), + |> dict.merge(from: shellout.color(["pink"])), custom: util.lookups, ) |> Some @@ -336,7 +336,7 @@ pub fn info(config: Toml) -> Result { "rad" |> shellout.style( with: shellout.display(["bold", "italic"]) - |> dict.merge(from: shellout.color(["pink"])), + |> dict.merge(from: shellout.color(["pink"])), custom: util.lookups, ) |> Some @@ -360,19 +360,19 @@ pub fn info(config: Toml) -> Result { |> result.map(with: shellout.style( _, with: shellout.display(["italic"]) - |> dict.merge(from: shellout.color(["purple"])), + |> dict.merge(from: shellout.color(["purple"])), custom: util.lookups, )) |> option.from_result [ [name, version] - |> option.values - |> string.join(with: " ") - |> Some, + |> option.values + |> string.join(with: " ") + |> Some, [Some(""), description] - |> option.all - |> option.map(with: string.join(_, with: tab)), + |> option.all + |> option.map(with: string.join(_, with: tab)), ] |> option.values |> string.join(with: "\n") @@ -385,7 +385,7 @@ pub fn heading(name: String) -> String { name |> shellout.style( with: shellout.display(["bold"]) - |> dict.merge(from: shellout.color([heading_color])), + |> dict.merge(from: shellout.color([heading_color])), custom: util.lookups, ) } diff --git a/src/rad/workbook/standard.gleam b/src/rad/workbook/standard.gleam index 6b733b7..e524602 100644 --- a/src/rad/workbook/standard.gleam +++ b/src/rad/workbook/standard.gleam @@ -80,23 +80,23 @@ pub fn workbook() -> Workbook { #( "display", flag.string_list() - |> flag.default(of: ["bold"]) - |> flag.description(of: "Set display styles") - |> flag.build, + |> flag.default(of: ["bold"]) + |> flag.description(of: "Set display styles") + |> flag.build, ), #( "color", flag.string_list() - |> flag.default(of: ["pink"]) - |> flag.description(of: "Set a foreground color") - |> flag.build, + |> flag.default(of: ["pink"]) + |> flag.description(of: "Set a foreground color") + |> flag.build, ), #( "background", flag.string_list() - |> flag.default(of: []) - |> flag.description(of: "Set a background color") - |> flag.build, + |> flag.default(of: []) + |> flag.description(of: "Set a background color") + |> flag.build, ), ] @@ -109,18 +109,18 @@ pub fn workbook() -> Workbook { #( "target", flag.string_list() - |> flag.default( - of: ["rad", "targets"] - |> toml.decode(from: toml, expect: dynamic.list(of: dynamic.string)) - |> result.lazy_or(fn() { - ["target"] - |> toml.decode(from: toml, expect: dynamic.string) - |> result.map(with: fn(target) { [target] }) - }) - |> result.unwrap(or: ["erlang"]), - ) - |> flag.description(of: "The platforms to target") - |> flag.build, + |> flag.default( + of: ["rad", "targets"] + |> toml.decode(from: toml, expect: dynamic.list(of: dynamic.string)) + |> result.lazy_or(fn() { + ["target"] + |> toml.decode(from: toml, expect: dynamic.string) + |> result.map(with: fn(target) { [target] }) + }) + |> result.unwrap(or: ["erlang"]), + ) + |> flag.description(of: "The platforms to target") + |> flag.build, ), ] @@ -128,9 +128,9 @@ pub fn workbook() -> Workbook { #( "all", flag.bool() - |> flag.default(of: False) - |> flag.description(of: "Run the task for all packages") - |> flag.build, + |> flag.default(of: False) + |> flag.description(of: "Run the task for all packages") + |> flag.build, ), ] @@ -138,16 +138,16 @@ pub fn workbook() -> Workbook { #( "no-docs", flag.bool() - |> flag.default(of: False) - |> flag.description(of: "Disable docs handling") - |> flag.build, + |> flag.default(of: False) + |> flag.description(of: "Disable docs handling") + |> flag.build, ), #( "port", flag.int() - |> flag.default(of: 7000) - |> flag.description(of: "Request live reloads over port (default 7000)") - |> flag.build, + |> flag.default(of: 7000) + |> flag.description(of: "Request live reloads over port (default 7000)") + |> flag.build, ), ..target_flags ] @@ -411,14 +411,14 @@ pub fn root(input: CommandInput, task: Task(Result)) -> Result { #( "bare", flag.bool() - |> flag.default(of: False) - |> flag.build, + |> flag.default(of: False) + |> flag.build, ), ] |> flag.build_map let version = fn(args) { args - |> CommandInput(flags: flags) + |> CommandInput(flags: flags, named_args: dict.new()) |> version(task) } ["rad"] @@ -455,19 +455,22 @@ pub fn docs_build(input: CommandInput, task: Task(Result)) -> Result { |> result.unwrap(or: False) use #(name, is_self) <- result.try( - self_or_dependency(input, task, self: fn(self, _config) { Ok(self) }, or: fn( - config, - ) { - case all { - True -> - input.args - |> list.first - |> result.replace_error(snag.new("no package found")) - False -> - input.args - |> dependency_name(from: config) - } - }), + self_or_dependency( + input, + task, + self: fn(self, _config) { Ok(self) }, + or: fn(config) { + case all { + True -> + input.args + |> list.first + |> result.replace_error(snag.new("no package found")) + False -> + input.args + |> dependency_name(from: config) + } + }, + ), ) let path = case is_self { @@ -516,7 +519,7 @@ pub fn docs_build(input: CommandInput, task: Task(Result)) -> Result { let _print = [ " Skipping" - |> shellout.style(with: shellout.color(["magenta"]), custom: []), + |> shellout.style(with: shellout.color(["magenta"]), custom: []), name, ] |> string.join(with: " ") @@ -526,7 +529,7 @@ pub fn docs_build(input: CommandInput, task: Task(Result)) -> Result { "", "No gleam.toml file was found in", [path, "/"] - |> string.concat, + |> string.concat, ] |> string.join(with: "\n") |> io.println @@ -629,7 +632,7 @@ pub fn format(input: CommandInput, task: Task(Result)) -> Result { use result <- result.try( dict.new() - |> CommandInput(args: []) + |> CommandInput(args: [], named_args: dict.new()) |> task.basic(input.args)(task) |> result.map_error(with: fn(_snag) { let check = @@ -791,11 +794,7 @@ fn do_ping(uri_string: String, headers: List(Header)) -> gleam.Result(Int, Int) let script = [ - "fetch('" - <> uri_string - <> "', " - <> headers - <> ")", + "fetch('" <> uri_string <> "', " <> headers <> ")", ".then(response => response.status)", ".catch(() => 503)", ".then(console.log)", @@ -871,9 +870,7 @@ fn do_shell(input: CommandInput, task: Task(Result)) -> Result { } let javascript = [ - "import('" - <> util.rad_path - <> "/rad_ffi.mjs')", + "import('" <> util.rad_path <> "/rad_ffi.mjs')", ".then(module => module.load_modules())", ] |> string.concat @@ -889,22 +886,14 @@ fn do_shell(input: CommandInput, task: Task(Result)) -> Result { util.ebin_paths() |> result.replace_error(snag.new("failed to find `ebin` paths")), ) - [ - [ - "--eval", - "Application.ensure_all_started(:" - <> name - <> ") + [["--eval", "Application.ensure_all_started(:" <> name <> ") :code.all_available() |> Enum.map(fn {module, _, _} -> List.to_atom(module) end) - |> :code.ensure_modules_loaded", - ], - [ + |> :code.ensure_modules_loaded"], [ "--erl", ["-pa", ..ebins] - |> string.join(with: " "), - ], - ] + |> string.join(with: " "), + ]] |> list.concat |> shellout.command(run: "iex", in: ".", opt: options) |> result.replace_error(snag.new("failed to run `elixir` shell")) @@ -923,8 +912,7 @@ fn do_shell(input: CommandInput, task: Task(Result)) -> Result { "nodejs" | "node" -> [ "--interactive", - "--eval=" - <> javascript, + "--eval=" <> javascript, "--experimental-fetch", "--experimental-repl-await", "--no-warnings", @@ -1019,7 +1007,7 @@ pub fn tree(_input: CommandInput, _task: Task(Result)) -> Result { "--git", "--git-ignore", ["--ignore-glob=", ignore_glob] - |> string.concat, + |> string.concat, "--long", "--no-filesize", "--no-permissions", @@ -1175,9 +1163,9 @@ fn do_watch(input: CommandInput) -> Result { [ " Watching" - |> shellout.style(with: shellout.color(["magenta"]), custom: util.lookups), + |> shellout.style(with: shellout.color(["magenta"]), custom: util.lookups), " … " - |> shellout.style(with: shellout.color(["cyan"]), custom: util.lookups), + |> shellout.style(with: shellout.color(["cyan"]), custom: util.lookups), "(Ctrl+C to quit)", ] |> string.concat @@ -1186,11 +1174,11 @@ fn do_watch(input: CommandInput) -> Result { let result = [ ignore_glob - |> string.split(on: "|") - |> list.map(with: fn(directory) { - ["--ignore=**/", directory, "/**"] - |> string.concat - }), + |> string.split(on: "|") + |> list.map(with: fn(directory) { + ["--ignore=**/", directory, "/**"] + |> string.concat + }), ["--no-shell"], ["--postpone"], ["--watch-when-idle"], @@ -1212,7 +1200,7 @@ fn do_watch(input: CommandInput) -> Result { [ "--exclude", ["^[./\\\\]*(", ignore_glob, ")([/\\\\].*)*$"] - |> string.concat, + |> string.concat, ], ["-qq"], ["--recursive"], @@ -1284,10 +1272,10 @@ pub fn watch_do(input: CommandInput, _task: Task(Result)) -> Result { False -> { [ " Generating" - |> shellout.style( - with: shellout.color(["magenta"]), - custom: util.lookups, - ), + |> shellout.style( + with: shellout.color(["magenta"]), + custom: util.lookups, + ), "documentation", ] |> string.join(with: " ") @@ -1301,7 +1289,7 @@ pub fn watch_do(input: CommandInput, _task: Task(Result)) -> Result { |> string.concat let _result = [uri_string] - |> CommandInput(flags: dict.new()) + |> CommandInput(flags: dict.new(), named_args: dict.new()) |> ping(task.new(at: [], run: fn(_input, _task) { Ok("") })) Nil } @@ -1312,7 +1300,7 @@ pub fn watch_do(input: CommandInput, _task: Task(Result)) -> Result { |> workbook.get(["test"]) [#("target", target_flag)] |> dict.from_list - |> CommandInput(args: input.args) + |> CommandInput(args: input.args, named_args: dict.new()) |> task.trainer(tests)(task) } @@ -1335,60 +1323,60 @@ fn hello_lucy(input: CommandInput, _task: Task(Result)) -> Result { " |> shellout.style( with: style_flags(input.flags) - |> dict.merge(from: shellout.display(["bold", "italic"])), + |> dict.merge(from: shellout.display(["bold", "italic"])), custom: util.lookups, ) let sparkles = shellout.style( _, with: shellout.display(["bold", "italic"]) - |> dict.merge(from: shellout.color(["buttercup"])), + |> dict.merge(from: shellout.color(["buttercup"])), custom: util.lookups, ) let hello_joe = [ " ", "✨" - |> sparkles, + |> sparkles, "Hello, world!" - |> shellout.style( - with: shellout.display(["bold", "italic"]) - |> dict.merge(from: shellout.color(["purple"])), - custom: util.lookups, - ), + |> shellout.style( + with: shellout.display(["bold", "italic"]) + |> dict.merge(from: shellout.color(["purple"])), + custom: util.lookups, + ), "✨" - |> sparkles, + |> sparkles, ] |> string.join(with: " ") let welcome = [ "Welcome to ", "Gleam" - |> shellout.style( - with: shellout.display(["bold"]) - |> dict.merge(shellout.color(["pink"])), - custom: util.lookups, - ), + |> shellout.style( + with: shellout.display(["bold"]) + |> dict.merge(shellout.color(["pink"])), + custom: util.lookups, + ), "! It's great to have you.", ] |> string.concat let uri = shellout.style( _, with: shellout.display(["italic"]) - |> dict.merge(from: shellout.color(["boi-blue"])), + |> dict.merge(from: shellout.color(["boi-blue"])), custom: util.lookups, ) let website = [ "https://" - |> uri, + |> uri, "gleam.run" - |> shellout.style( - with: shellout.display(["italic"]) - |> dict.merge(shellout.color(["pink"])), - custom: util.lookups, - ), + |> shellout.style( + with: shellout.display(["italic"]) + |> dict.merge(shellout.color(["pink"])), + custom: util.lookups, + ), "/documentation/" - |> uri, + |> uri, ] |> string.concat [ diff --git a/test/rad/task_test.gleam b/test/rad/task_test.gleam index a7e1b4b..c1e5b6a 100644 --- a/test/rad/task_test.gleam +++ b/test/rad/task_test.gleam @@ -66,30 +66,30 @@ pub fn builder_test() { let #(_name, flag1_contents) as flag1 = #( "all", flag.bool() - |> flag.default(of: False) - |> flag.description(of: "For one") - |> flag.build, + |> flag.default(of: False) + |> flag.description(of: "For one") + |> flag.build, ) let flags = [ #( "one", flag.string() - |> flag.default(of: "for") - |> flag.description(of: "All") - |> flag.build, + |> flag.default(of: "for") + |> flag.description(of: "All") + |> flag.build, ), #( "target", flag.string_list() - |> flag.default(of: ["erlang"]) - |> flag.build, + |> flag.default(of: ["erlang"]) + |> flag.build, ), ] let #(_name, flag4_contents) as flag4 = #( "zero", flag.int() - |> flag.default(of: 0) - |> flag.build, + |> flag.default(of: 0) + |> flag.build, ) let parameter1 = #("[g]", "") let parameters = [#("[h]", ""), #("[i]", "Some j")] @@ -305,7 +305,7 @@ fn iterable_input() { |> dict.from_list |> flag.update_flags(with: "--target=erlang,javascript") ["a", "b", "c"] - |> CommandInput(flags: flags) + |> CommandInput(flags: flags, named_args: dict.new()) } fn iterable_flags() { @@ -313,26 +313,26 @@ fn iterable_flags() { #( "rad-test", flag.bool() - |> flag.default(of: True) - |> flag.build, + |> flag.default(of: True) + |> flag.build, ), #( "all", flag.bool() - |> flag.default(of: False) - |> flag.build, + |> flag.default(of: False) + |> flag.build, ), #( "check", flag.bool() - |> flag.default(of: False) - |> flag.build, + |> flag.default(of: False) + |> flag.build, ), #( "target", flag.string_list() - |> flag.default(of: ["erlang"]) - |> flag.build, + |> flag.default(of: ["erlang"]) + |> flag.build, ), ] } diff --git a/test/rad/util_test.gleam b/test/rad/util_test.gleam index ab79c0f..41f05af 100644 --- a/test/rad/util_test.gleam +++ b/test/rad/util_test.gleam @@ -122,50 +122,50 @@ pub fn relay_flags_test() { #( "rad-test", flag.bool() - |> flag.default(of: True) - |> flag.build, + |> flag.default(of: True) + |> flag.build, ), #( "eevee", flag.bool() - |> flag.default(of: False) - |> flag.build, + |> flag.default(of: False) + |> flag.build, ), #( "vaporeon", flag.float() - |> flag.default(of: 1.0) - |> flag.build, + |> flag.default(of: 1.0) + |> flag.build, ), #( "jolteon", flag.float_list() - |> flag.default(of: [2.0, 0.2]) - |> flag.build, + |> flag.default(of: [2.0, 0.2]) + |> flag.build, ), #( "flareon", flag.int() - |> flag.default(of: 3) - |> flag.build, + |> flag.default(of: 3) + |> flag.build, ), #( "espeon", flag.int_list() - |> flag.default(of: [4, 0, 4]) - |> flag.build, + |> flag.default(of: [4, 0, 4]) + |> flag.build, ), #( "umbreon", flag.string() - |> flag.default(of: "5") - |> flag.build, + |> flag.default(of: "5") + |> flag.build, ), #( "ditto", flag.string_list() - |> flag.default(of: ["eevee"]) - |> flag.build, + |> flag.default(of: ["eevee"]) + |> flag.build, ), ] |> flag.build_map diff --git a/test/rad/workbook/standard_test.gleam b/test/rad/workbook/standard_test.gleam index 001392f..6d7d8d5 100644 --- a/test/rad/workbook/standard_test.gleam +++ b/test/rad/workbook/standard_test.gleam @@ -41,8 +41,8 @@ pub fn root_test() { #( "version", flag.bool() - |> flag.default(of: False) - |> flag.build, + |> flag.default(of: False) + |> flag.build, ), ] @@ -113,8 +113,8 @@ pub fn name_test() { #( "all", flag.bool() - |> flag.default(of: False) - |> flag.build, + |> flag.default(of: False) + |> flag.build, ), ] let task = @@ -208,14 +208,14 @@ pub fn version_test() { #( "all", flag.bool() - |> flag.default(of: False) - |> flag.build, + |> flag.default(of: False) + |> flag.build, ), #( "bare", flag.bool() - |> flag.default(of: False) - |> flag.build, + |> flag.default(of: False) + |> flag.build, ), ] let task = diff --git a/test/rad/workbook_test.gleam b/test/rad/workbook_test.gleam index 457fe3b..ab7415f 100644 --- a/test/rad/workbook_test.gleam +++ b/test/rad/workbook_test.gleam @@ -18,11 +18,11 @@ pub fn from_tasks_test() { [ [] - |> task.new(run: task.basic(["echo"])), + |> task.new(run: task.basic(["echo"])), ["igglybuff"] - |> task.new(run: task.basic(["echo"])), + |> task.new(run: task.basic(["echo"])), ["jigglypuff", "wigglytuff"] - |> task.new(run: task.basic(["echo"])), + |> task.new(run: task.basic(["echo"])), ] |> workbook.from_tasks |> dict.size @@ -43,11 +43,11 @@ pub fn builder_test() { let workbook = [ [] - |> task.new(run: task.basic(["echo"])), + |> task.new(run: task.basic(["echo"])), ["cleffa"] - |> task.new(run: task.basic(["echo"])), + |> task.new(run: task.basic(["echo"])), ["clefairy", "clefable"] - |> task.new(run: task.basic(["echo"])), + |> task.new(run: task.basic(["echo"])), ] |> workbook.tasks(into: workbook.new()) diff --git a/test/rad_test.gleam b/test/rad_test.gleam index da6c127..82e5299 100644 --- a/test/rad_test.gleam +++ b/test/rad_test.gleam @@ -38,8 +38,8 @@ pub fn input( #( "rad-test", flag.bool() - |> flag.default(of: True) - |> flag.build, + |> flag.default(of: True) + |> flag.build, ), ..flags ] @@ -47,26 +47,26 @@ pub fn input( let ArgAcc(flags: new_flags, args: args, ..) = args - |> list.fold(from: ArgAcc(flags: [], args: [], maybe_flag: True), with: fn( - acc, - arg, - ) { - case arg, acc.maybe_flag, string.starts_with(arg, flag.prefix) { - "--", True, _ -> ArgAcc(..acc, maybe_flag: False) - _else_if, True, True -> - ArgAcc( - ..acc, - flags: acc.flags - |> list.append([arg]), - ) - _else, _, _ -> - ArgAcc( - ..acc, - args: acc.args - |> list.append([arg]), - ) - } - }) + |> list.fold( + from: ArgAcc(flags: [], args: [], maybe_flag: True), + with: fn(acc, arg) { + case arg, acc.maybe_flag, string.starts_with(arg, flag.prefix) { + "--", True, _ -> ArgAcc(..acc, maybe_flag: False) + _else_if, True, True -> + ArgAcc( + ..acc, + flags: acc.flags + |> list.append([arg]), + ) + _else, _, _ -> + ArgAcc( + ..acc, + args: acc.args + |> list.append([arg]), + ) + } + }, + ) new_flags |> list.fold(from: flags, with: fn(acc, flag) { @@ -74,7 +74,7 @@ pub fn input( |> flag.update_flags(with: flag) |> result.unwrap(or: acc) }) - |> CommandInput(args: args) + |> CommandInput(args: args, named_args: dict.new()) } pub fn task(from workbook: Workbook, at path: List(String)) -> Task(Result) {