From 82be6eb4d453c39602a0aa5a6fc8582ae95799e8 Mon Sep 17 00:00:00 2001 From: "a.stevan" <antoine.stevan@isae-supaero.fr> Date: Thu, 21 Nov 2024 15:14:50 +0100 Subject: [PATCH 1/2] add argument checks --- benchmarks/nu-lib/commit.nu | 7 +++---- benchmarks/nu-lib/fec/run.nu | 8 ++++---- benchmarks/nu-lib/linalg.nu | 6 ++---- benchmarks/nu-lib/recoding.nu | 8 ++++---- benchmarks/nu-lib/setup.nu | 7 +++---- benchmarks/nu-lib/utils/args.nu | 24 ++++++++++++++++++++++++ benchmarks/nu-lib/utils/mod.nu | 1 + 7 files changed, 41 insertions(+), 20 deletions(-) create mode 100644 benchmarks/nu-lib/utils/args.nu diff --git a/benchmarks/nu-lib/commit.nu b/benchmarks/nu-lib/commit.nu index 8cb0d6bb..0d9cd4c5 100644 --- a/benchmarks/nu-lib/commit.nu +++ b/benchmarks/nu-lib/commit.nu @@ -2,6 +2,7 @@ use utils log use utils math * use utils fs check-file use utils plot [ into-axis-options, COMMON_OPTIONS, gplt ] +use utils args check-list-arg use std formats * @@ -17,10 +18,8 @@ export def run [ ]: list<int> -> path { let input = $in - if ($input | is-empty) or ($curves | is-empty) { - print "nothing to do" - return - } + $curves | check-list-arg --cmd "commit run" --arg "--curves" --span (metadata $curves).span + $in | check-list-arg --cmd "commit run" --arg "pipeline input" let new_file = $output == null let output = $output | default (mktemp --tmpdir komodo_commit.XXXXXX) diff --git a/benchmarks/nu-lib/fec/run.nu b/benchmarks/nu-lib/fec/run.nu index cb814411..4210ffc5 100644 --- a/benchmarks/nu-lib/fec/run.nu +++ b/benchmarks/nu-lib/fec/run.nu @@ -1,5 +1,6 @@ use ../utils log use ../utils formats * +use ../utils args check-list-arg use std formats * @@ -16,10 +17,9 @@ export def main [ ]: list<int> -> path { let input = $in - if ($ks | is-empty) or ($input | is-empty) or ($curves | is-empty) { - print "nothing to do" - return - } + $ks | check-list-arg --cmd "fec run" --arg "--ks" --span (metadata $ks).span + $curves | check-list-arg --cmd "fec run" --arg "--curves" --span (metadata $curves).span + $in | check-list-arg --cmd "fec run" --arg "pipeline input" let new_file = $output == null let output = $output | default (mktemp --tmpdir komodo_fec.XXXXXX) diff --git a/benchmarks/nu-lib/linalg.nu b/benchmarks/nu-lib/linalg.nu index 3bec71f3..a31085a8 100644 --- a/benchmarks/nu-lib/linalg.nu +++ b/benchmarks/nu-lib/linalg.nu @@ -2,6 +2,7 @@ use utils log use utils math * use utils fs check-file use utils plot [ into-axis-options, COMMON_OPTIONS, gplt ] +use utils args check-list-arg use std formats * @@ -16,10 +17,7 @@ export def run [ ]: list<int> -> path { let input = $in - if ($input | is-empty) { - print "nothing to do" - return - } + $in | check-list-arg --cmd "linalg run" --arg "pipeline input" let new_file = $output == null let output = $output | default (mktemp --tmpdir komodo_linalg.XXXXXX) diff --git a/benchmarks/nu-lib/recoding.nu b/benchmarks/nu-lib/recoding.nu index c8dcec3b..3c0f2390 100644 --- a/benchmarks/nu-lib/recoding.nu +++ b/benchmarks/nu-lib/recoding.nu @@ -3,6 +3,7 @@ use utils formats * use utils math * use utils plot [ into-axis-options, COMMON_OPTIONS, gplt ] use utils fs check-file +use utils args check-list-arg use std formats * @@ -19,10 +20,9 @@ export def run [ ]: list<int> -> path { let input = $in - if ($ks | is-empty) or ($input | is-empty) or ($curves | is-empty) { - print "nothing to do" - return - } + $ks | check-list-arg --cmd "recoding run" --arg "--ks" --span (metadata $ks).span + $curves | check-list-arg --cmd "recoding run" --arg "--curves" --span (metadata $curves).span + $in | check-list-arg --cmd "recoding run" --arg "pipeline input" let new_file = $output == null let output = $output | default (mktemp --tmpdir komodo_recoding.XXXXXX) diff --git a/benchmarks/nu-lib/setup.nu b/benchmarks/nu-lib/setup.nu index 4c747f57..37f105ad 100644 --- a/benchmarks/nu-lib/setup.nu +++ b/benchmarks/nu-lib/setup.nu @@ -2,6 +2,7 @@ use utils log use utils math * use utils fs check-file use utils plot [ into-axis-options, COMMON_OPTIONS, gplt ] +use utils args check-list-arg use std formats * @@ -17,10 +18,8 @@ export def run [ ]: list<int> -> path { let input = $in - if ($input | is-empty) or ($curves | is-empty) { - print "nothing to do" - return - } + $curves | check-list-arg --cmd "setup run" --arg "--curves" --span (metadata $curves).span + $in | check-list-arg --cmd "setup run" --arg "pipeline input" let new_file = $output == null let output = $output | default (mktemp --tmpdir komodo_setup.XXXXXX) diff --git a/benchmarks/nu-lib/utils/args.nu b/benchmarks/nu-lib/utils/args.nu new file mode 100644 index 00000000..9ec1fe3b --- /dev/null +++ b/benchmarks/nu-lib/utils/args.nu @@ -0,0 +1,24 @@ +# throws an error if the input is an empty list +export def check-list-arg [ + --cmd: string, # the name of the command + --arg: string, # the name of the argument + --span: record<start: int, end: int>, # the span of the arg (no span means an unspanned error) +]: [ list -> nothing ] { + if ($in | is-empty) { + if $span == null { + error make --unspanned { + msg: $"(ansi red_bold)invalid_arguments(ansi reset)", + help: $"provide a non empty list as ($arg)", + } + } else { + error make { + msg: $"(ansi red_bold)invalid_arguments(ansi reset)", + label: { + text: $"(ansi purple)($cmd)(ansi reset) needs (ansi purple)($arg)(ansi reset)", + span: $span + }, + help: $"provide a non empty list as (ansi purple)($arg)(ansi reset)" + } + } + } +} diff --git a/benchmarks/nu-lib/utils/mod.nu b/benchmarks/nu-lib/utils/mod.nu index 503415a0..c9e5c2bf 100644 --- a/benchmarks/nu-lib/utils/mod.nu +++ b/benchmarks/nu-lib/utils/mod.nu @@ -4,3 +4,4 @@ export module log.nu export module math.nu export module parse.nu export module plot.nu +export module args.nu -- GitLab From 0057edeea640e2b0d8e2f4fc56a12f9e298b4508 Mon Sep 17 00:00:00 2001 From: "a.stevan" <antoine.stevan@isae-supaero.fr> Date: Thu, 21 Nov 2024 15:15:42 +0100 Subject: [PATCH 2/2] add more descriptive error message --- benchmarks/nu-lib/fri/plot.nu | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmarks/nu-lib/fri/plot.nu b/benchmarks/nu-lib/fri/plot.nu index 7eb2287e..eba787a6 100644 --- a/benchmarks/nu-lib/fri/plot.nu +++ b/benchmarks/nu-lib/fri/plot.nu @@ -88,7 +88,7 @@ export def main [ --dump-dir: path = "./", ] { if ($x | is-empty) { - error make --unspanned { msg: "nothing to do" } + error make --unspanned { msg: "nothing to do, x is empty" } } if $file == null { error make --unspanned { msg: "missing --file" } -- GitLab