Create a Simple CLI Argument Parser
Turn process.argv flags of the form --key=value into an object, treating a bare --key as true.
const args = process.argv.slice(2);
const flags = Object.fromEntries(args.map((a) => {
const [k, v = "true"] = a.replace(/^--/, "").split("=");
return [k, v];
}));
console.log(flags);
Caveats
Only handles --key and --key=value. No short flags, quoting, or repeated keys (later values overwrite). Positional arguments become keys too.