Skip to content

Commit

Permalink
add an arguments count check to the run all command
Browse files Browse the repository at this point in the history
  • Loading branch information
TanklesXL committed Mar 6, 2024
1 parent 726533c commit c38e6d2
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions src/gladvent/internal/cmd/run.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ fn gleam_err_to_string(g: GleamErr) -> String {
"at line",
int.to_string(g.line),
g.value
|> option.map(fn(val) { "with value " <> string.inspect(val) })
|> option.unwrap(""),
|> option.map(fn(val) { "with value " <> string.inspect(val) })
|> option.unwrap(""),
],
" ",
)
Expand Down Expand Up @@ -259,6 +259,10 @@ pub fn run_command() -> glint.Command(Result(List(String))) {
use input <- glint.command()
let assert Ok(year) = flag.get_int(input.flags, cmd.year)
let assert Ok(allow_crash) = flag.get_bool(input.flags, allow_crash)
let timing =
flag.get_int(input.flags, timeout)
|> result.map(Ending)
|> result.unwrap(Endless)

use days <- result.then(parse.days(input.args))
use package <- result.then(
Expand All @@ -267,11 +271,10 @@ pub fn run_command() -> glint.Command(Result(List(String))) {
)

days
|> cmd.exec(
timing(input.flags),
do(year, _, package, allow_crash),
collect_async(year, _),
)
|> cmd.exec(timing, do(year, _, package, allow_crash), collect_async(
year,
_,
))
|> Ok
}
|> glint.flag(timeout, timeout_flag())
Expand All @@ -283,8 +286,12 @@ pub fn run_command() -> glint.Command(Result(List(String))) {
pub fn run_all_command() -> glint.Command(Result(List(String))) {
{
use input <- glint.command()
let assert Ok(allow_crash) = flag.get_bool(input.flags, allow_crash)
let assert Ok(year) = flag.get_int(input.flags, cmd.year)
let assert Ok(allow_crash) = flag.get_bool(input.flags, allow_crash)
let timing =
flag.get_int(input.flags, timeout)
|> result.map(Ending)
|> result.unwrap(Endless)

use package <- result.then(
runners.pkg_interface()
Expand All @@ -294,29 +301,23 @@ pub fn run_all_command() -> glint.Command(Result(List(String))) {
package.modules
|> map.keys
|> list.filter_map(fn(k) {
k
|> string.split_once("aoc_" <> int.to_string(year) <> "/day_")
|> result.try(fn(day) {
day.1
|> parse.day
|> result.replace_error(Nil)
})
use day <- result.try(string.split_once(
k,
"aoc_" <> int.to_string(year) <> "/day_",
))
day.1
|> parse.day
|> result.replace_error(Nil)
})
|> list.sort(int.compare)
|> cmd.exec(
timing(input.flags),
do(year, _, package, allow_crash),
collect_async(year, _),
)
|> cmd.exec(timing, do(year, _, package, allow_crash), collect_async(
year,
_,
))
|> Ok
}
|> glint.flag(timeout, timeout_flag())
|> glint.flag(allow_crash, allow_crash_flag())
|> glint.description("Run all registered days")
}

fn timing(flags: flag.Map) {
flag.get_int(flags, timeout)
|> result.map(Ending)
|> result.unwrap(Endless)
|> glint.unnamed_args(glint.EqArgs(0))
}

0 comments on commit c38e6d2

Please sign in to comment.