Modern argument parsing, with colors, made easy.
npm i https://github.com/neverUsedGithub/Argue
import argue from "argue";
const ctx =
argue({
name: "greeter"
})
.opt({
name: "-n, --name",
accepts: "string",
default: "World"
})
.parse(process.argv.slice(2));
// Argue automatically created argv with the correct types
console.log(ctx.argv.name);
const ctx =
argue({
name: "server",
describe: "A server cli.",
})
.command({
name: "serve",
help: "serve [port]",
describe: "Start a server on the specified port."
}, argue => argue
.pos({
name: "port",
describe: "The port to listen on.",
accepts: "number",
default: 3000
})
)
.opt({
name: "-v, --verbose",
describe: "Use verbose logging.",
accepts: "boolean",
default: false
})
.parse(process.argv.slice(2));
if (ctx.command === "none")
console.log(ctx.argv.port) // errors
// ctx.command is the command that was used or "none"
console.log(
ctx.command /* "none" | "serve" */,
ctx.argv /* { verbose: boolean } | { port: number } */
);