Run parseArger commands in JavaScript/browser environments using just-bash.
bun add parsearger-js just-bash
# or
npm install parsearger-js just-bashImportant:
just-bashis a peer dependency and must be installed alongside this package.
import { ParseArger } from "parsearger-js";
const pa = new ParseArger();
// Generate a bash script with argument parsing
const result = await pa.generate({
pos: [{ name: "input", description: "Input file to process" }],
opt: [{ name: "output", description: "Output file", short: "o" }],
flag: [{ name: "verbose", description: "Enable verbose output", short: "v" }],
helpMessage: "Process files with style",
setVersion: "1.0.0",
});
console.log(result.stdout); // Generated bash script
console.log(result.exitCode); // 0 on successconst pa = new ParseArger();
// Execute any parseArger command directly
const result = await pa.exec(
'generate --pos "file \\"input file\\"" --flag "debug \\"enable debug\\""',
);
console.log(result.stdout);// Import from browser entry point
import { ParseArger } from "parsearger-js/browser";
const pa = new ParseArger();
const result = await pa.generate({
pos: [{ name: "name", description: "Your name" }],
});Add new arguments to an existing parseArger script:
const pa = new ParseArger();
const existingScript = `#!/bin/bash
# @parseArger-begin
# @parseArger-help "My script"
# ... existing parseArger content
`;
const result = await pa.parse(existingScript, {
opt: [{ name: "config", description: "Config file", short: "c" }],
inplace: false,
});const pa = new ParseArger();
const script = `#!/bin/bash
# @parseArger-begin
# ...parseArger script content
`;
const docs = await pa.document(script, {
title: "My Tool Documentation",
titleTag: "##",
});
console.log(docs.stdout); // Markdown documentationconst pa = new ParseArger();
const form = await pa.htmlForm(scriptContent, {
title: "Script Configuration",
});
console.log(form.stdout); // HTML formCreate a new ParseArger instance.
options.files- Additional files to include in the virtual filesystemoptions.cwd- Working directory (default:/home/user)
Generate a new parseArger script.
Options:
pos- Positional argumentsopt- Optional argumentsflag- Flag argumentshelpMessage- Help messagesetVersion- Version stringbang- Include shebang (default: true)useVerbose- Include verbose handling (default: true)- ... and more (see types)
Parse an existing script and add arguments.
Generate markdown documentation for a script.
Generate an HTML form for a script.
Execute a raw parseArger command.
Get the underlying just-bash instance for advanced usage.
Write a file to the virtual filesystem.
Read a file from the virtual filesystem.
interface PositionalArg {
name: string;
description: string;
optional?: boolean;
repeat?: boolean;
repeatMin?: number; // Minimum repetitions (forces repeat)
repeatMax?: number; // Maximum repetitions (forces repeat)
oneOf?: string[];
subcommand?: boolean;
subcommandDirectory?: string;
}
interface OptionalArg {
name: string;
description: string;
short?: string;
defaultValue?: string;
repeat?: boolean;
repeatMin?: number; // Minimum repetitions
repeatMax?: number; // Maximum repetitions
oneOf?: string[];
alias?: string[];
emptyValue?: string; // Value when option is used without argument
empty?: boolean;
}
interface FlagArg {
name: string;
description: string;
short?: string;
on?: boolean;
noName?: string;
alias?: string[];
noAlias?: string[]; // Negation aliases
}
interface ParseArgerResult {
stdout: string;
stderr: string;
exitCode: number;
}- Teaching Sandbox: Create interactive bash scripting tutorials
- AI Agents: Generate bash scripts programmatically
- Web Tools: Build online parseArger script generators
- Testing: Test parseArger behavior in isolation
# Install dependencies
bun install
# Embed parseArger scripts
bun run embed-scripts
# Build
bun run build
# Run tests
bun test
# Type check
bun run typecheckMIT