Sujet : Re: Useless Use Of Regexes
De : ldo (at) *nospam* nz.invalid (Lawrence D'Oliveiro)
Groupes : comp.os.linux.miscDate : 27. Mar 2025, 00:50:43
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vs23sj$2s4s3$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9
User-Agent : Pan/0.162 (Pokrosvk)
On Wed, 26 Mar 2025 21:43:51 +0100, Marc Haber wrote:
Lawrence D'Oliveiro <ldo@nz.invalid> wrote:
>
On Wed, 26 Mar 2025 08:21:42 +0100, Marc Haber wrote:
It has become better since I usually start off with ChatGPT which
takes care of the boilerplate stuff.
>
The main point of using a very-high-level language (like bash) is that
you shouldn’t need any boilerplate stuff.
As soon as you make it flexlbie, with command line options, you begin
typing getopt or GetOptions stuff and that's pretty much boilerplate.
Well, I do do that. Mainly it’s just a loop, though, e.g.
for ((;;)); do
if [ "${1:0:2}" != "--" ]; then
break
fi
if [ "$1" == "--" ]; then
shift
break
fi
opt="${1:2:${#1}}"
shift
val="${opt#*=}"
if [ "$val" = "$opt" ]; then
val=""
fi
opt="${opt%%=*}"
if [ "$opt" = "animation" ]; then
animation=1
elif [ "$opt" = "blender" ]; then
blender="$val"
elif [ "$opt" = "camera" ]; then
camera="$val"
elif [ "$opt" = "collections" ]; then
collections="$val"
elif [ "$opt" = "crash-protect" ]; then
crash_protect=1
elif [ "$opt" = "crash-retry-count" ]; then
crash_retry_count="$val"
elif [ "$opt" = "digits" ]; then
digits="$val"
...
else
opterror "bad option $opt"
fi
done
I would say, only a few lines in there count as “boilerplate” ...