| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
A powerful, type-safe command line argument parser for Deno using modern decorators and inheritance.
import { arg, Args, cli, opt } from "@sigma/parse";
@cli({ name: "calculator", description: "A simple calculator" })
class Calculator extends Args {
@arg({ type: "number", description: "first number", required: true })
a!: number;
@arg({ type: "number", description: "second number", required: true })
b!: number;
@opt({ description: "operation to perform" })
operation = "add";
}
// Parse command line arguments
const args = Calculator.parse(["10", "5", "--operation", "multiply"]);
// Use the required values directly
console.log(`${args.a} ${args.operation} ${args.b} = ...`);Your main command class must extend Args to get the static parse method:
import { Args, cli, opt } from "@sigma/parse";
@cli({ name: "myapp", description: "My application" })
class MyApp extends Args {
@opt({ description: "Enable verbose logging", short: "v" })
verbose = false;
@opt({ description: "Port number", type: "number" })
port = 8080;
}
const args = MyApp.parse(Deno.args);
console.log(args.verbose, args.port); // Fully typed!Subcommands are plain classes (no need to extend Args). Link them using @subCommand:
import { Args, cli, command, opt, subCommand } from "@sigma/parse";
@command
class ServeCommand {
@opt({ description: "Port to serve on" })
port = 3000;
@opt({ description: "Enable development mode", short: "d" })
dev = false;
}
@cli({ name: "myapp" })
class MyApp extends Args {
@subCommand(ServeCommand, { description: "Start development server" })
serve?: ServeCommand;
}
const args = MyApp.parse(["serve", "--port", "8080", "--dev"]);
if (args.serve) {
console.log(args.serve.port); // 8080
}Explicitly Required (must be provided on CLI):
@opt({ type: "string", required: true })
apiKey!: string;Optional with Default (inferred from value):
port = 8080; // type inferred as numberUse short: true to automatically use the first character of the property name as a short flag:
verbose = false; // becomes -v, --verboseimport { Args, cli, oneOf, opt, pattern, range, validate } from "@sigma/parse";
@cli({ name: "example" })
class Example extends Args {
@opt()
@validate(range(1, 100))
score = 50;
@opt()
@validate(oneOf(["dev", "prod"]))
env = "dev";
@opt()
@validate(pattern(/^[a-z]+$/))
user = "admin";
}Use raw: true to build wrappers that forward arguments to other tools:
@cli({ name: "proxy" })
class Proxy extends Args {
@arg({ description: "Command to run", required: true })
cmd!: string;
@arg({ raw: true })
args: string[] = [];
}
// Usage: proxy deno run --allow-net server.ts
// cmd = "deno"
// args = ["run", "--allow-net", "server.ts"]Generate Fish completion scripts automatically:
# Generate fish completions
deno run myapp.ts gen-completions fish > ~/.config/fish/completions/myapp.fishMIT License
| Back | FazBrowse Home | New Git URL |