3 ms·
when I write scripts in js or python over bash, its to leverage their access to data structures, error handling, and libraries. Often I use TypeScript, because
by Normal_gaussian 5y ago
when I write scripts in js or python over bash, its to leverage their access to data structures, error handling, and libraries. Often I use TypeScript, because types are good and concurrent i/o is a first class feature.
This means that promise.all probably looks something more like
const lastWeek = DateTime.now().minus({ days: 7 }).toISOString()
const pods = JSON.parse(await $`kubectl get pods -o json`)
useValidate(pods, isKubeCtlPodList)
await Promise.all(
pods.filter(pod => !protectedPods.includes(pod.name))
.filter(pod => target.test(pod.name))
.filter(pod => pod.created < lastWeek)
.map(pod => $`kubectl delete pod ${pod.name}`)
)
Id certainly encapsulte my calls, parsing, and validation differently in real code, but you get the gist.
In shell I can wrangle jq, date, xargs and get the same result; only this is waay easier to write, gives me validation and usable error messages, and can be altered much more easily than shell.
I write complex bash scripts somewhat often. They can be quicker to write, they are great for one-offs. But if I'm coming back to something non-trivial or if its getting deployed into production I want a language like js or python (or nearly any other language. C++, OCaml, Java all help more than they hinder).