skills/bun-guides-process-argv/SKILL.md
Parse command-line arguments
npx skillsauth add jarle/bun-skills Bun Parse command-line argumentsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
The argument vector is the list of arguments passed to the program when it is run. It is available as Bun.argv.
console.log(Bun.argv);
Running this file with arguments results in the following:
bun run cli.ts --flag1 --flag2 value
[ '/path/to/bun', '/path/to/cli.ts', '--flag1', '--flag2', 'value' ]
To parse argv into a more useful format, util.parseArgs would be helpful.
Example:
import { parseArgs } from "util";
const { values, positionals } = parseArgs({
args: Bun.argv,
options: {
flag1: {
type: "boolean",
},
flag2: {
type: "string",
},
},
strict: true,
allowPositionals: true,
});
console.log(values);
console.log(positionals);
then it outputs
bun run cli.ts --flag1 --flag2 value
{
flag1: true,
flag2: "value",
}
[ "/path/to/bun", "/path/to/cli.ts" ]
development
Using TypeScript with Bun, including type definitions and compiler options
development
Learn how to write tests using Bun's Jest-compatible API with support for async tests, timeouts, and various test modifiers
testing
Learn how to use snapshot testing in Bun to save and compare output between test runs
testing
Learn about Bun test's runtime integration, environment variables, timeouts, and error handling