diff --git a/benchmarks/nu-lib/commit.nu b/benchmarks/nu-lib/commit.nu index 8cb0d6bb0a4b5473d755ee41d35cd0c0bdab0f34..0d9cd4c594a8ddb3e17071cb6b06921527f218d7 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 cb8144114ceb8132a0508318a510713b4ef01661..4210ffc5973139190eaa2f964e6353fec02562c1 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/fri/plot.nu b/benchmarks/nu-lib/fri/plot.nu index 7eb2287e7f0394d30ae99c8eb95925208998635f..eba787a6ce0fd9917c327f62d471960ffe6c4ec8 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" } diff --git a/benchmarks/nu-lib/linalg.nu b/benchmarks/nu-lib/linalg.nu index 3bec71f3dbc9497281a8e68a999d815d329c3f46..a31085a82d97d5812964113c089fb805dc4b1f49 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 c8dcec3b18dc01a0744eb8e4fca6ae80a483ef56..3c0f2390d17c93df430f9443f2675c622e3c1422 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 4c747f57b0261e9d455e3b6442629bbfbe830b3d..37f105adb4a89edc933dff9b31be69e2493977f7 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 0000000000000000000000000000000000000000..9ec1fe3b6dbfea376f01131886ed1daf7014696a --- /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 503415a07d1079c305913f48888ed0798bdd274f..c9e5c2bf57eb590efb8bdab884bc4a852692275a 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