Simplify options parsing, (thanks dzaima)

This commit is contained in:
Rampoina 2023-03-05 23:35:15 +01:00
parent 276d6cd6ca
commit f3a164bbb5
1 changed files with 8 additions and 11 deletions

19
arc.bqn
View File

@ -7,25 +7,22 @@
opts{
a•args
_optl_{𝔾,𝔽 (»a𝕩)/a}
_opt_{ 𝔽_optl_𝔾 𝕩}
{𝕤
•Out "Usage: "•name" [OPTION]...
--help,-h: Display this help message
--levels,-l FILE: load levels from FILE
--chars,-c STRING: Characters to display for each game object, needs to have length 15
--fchars,-f STRING: Characters to represent each game object in the levels file, needs to have length 15
--start,-s N: Start directly at level number N
"
--start,-s N: Start directly at level number N"
•Exit 0
}((´"-h"<a)(´"--help"<a)) @
}´"-h""--help"a
c{0=𝕩?" λ$⊕⭍#/\-|+<>^v";𝕩}(»(<"--chars"))/a
f{0=𝕩?" λ$⊕⭍#/\-|+<>^v";𝕩}(»(<"--fchars"))/a
chars{0=𝕩?c;𝕩}(»(<"-c"))/a
fchars{0=𝕩?f;𝕩}(»(<"-f"))/a
l{0=𝕩?"levels";𝕩}(»(<"--levels"))/a
levels{0=𝕩?l;𝕩}(»(<"-l"))/a
s{0=𝕩?1;1𝕩}•BQN¨{𝕊: •Out "Invalid starting level number" •Exit 1}(»(<"-s"))/a
n{0=𝕩?s;1𝕩}•BQN¨{𝕊: •Out "Invalid starting level number" •Exit 1}(»(<"--start"))/a
chars _optl_" λ$⊕⭍#/\-|+<>^v" "-c""--chars"
fchars _optl_" λ$⊕⭍#/\-|+<>^v" "-f""--fchars"
levels _optl_"levels" "-l""--levels"
n{1•BQN{𝕊: •Out "Invalid starting level number" •Exit 1} 𝕩}_optl_ 1 "-s""--start"
}
gGame{𝕊: •Out •CurrentError @ •Exit 1} opts.nopts.levelsopts.charsopts.fcharsansi.defaultB,ansi.yellow,ansi.cyan,ansi.red