A powerful, type-safe command line argument parser for Deno using modern decorators and inheritance.
- Perfect Type Safety - Fully typed results based on your class definitions.
- Unified Decorators - Simplify configuration with
@optand@argobjects. - Explicit Flags - Clear distinction between CLI options and internal state.
- Subcommands - Hierarchical command structure with full type safety.
- Validation - Built-in and custom validators with easy composition.
- Shell Completions - Built-in support for generating shell completions (Fish).
import{arg,Args,cli,opt}from"@sigma/parse";
@cli({name: "calculator",description: "A simple calculator"})classCalculatorextendsArgs{
@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 argumentsconstargs=Calculator.parse(["10","5","--operation","multiply"]);// Use the required values directlyconsole.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"})classMyAppextendsArgs{
@opt({description: "Enable verbose logging",short: "v"})verbose=false;
@opt({description: "Port number",type: "number"})port=8080;}constargs=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";
@commandclassServeCommand{
@opt({description: "Port to serve on"})port=3000;
@opt({description: "Enable development mode",short: "d"})dev=false;}
@cli({name: "myapp"})classMyAppextendsArgs{
@subCommand(ServeCommand,{description: "Start development server"})serve?: ServeCommand;}constargs=MyApp.parse(["serve","--port","8080","--dev"]);if(args.serve){console.log(args.serve.port);// 8080}@cli(options)- Configure the main application entry point.@command(options?)- Mark a class as a command or subcommand handler.
@opt(options)- Mark a property as a CLI flag (--flag).description: Help text.type: Explicit type ("string","number","boolean","string[]","number[]").required: Mark as required.short: Short flag character (string) ortrueto auto-assign from the first letter.
@arg(options)- Mark a property as a positional argument.description: Help text.type: Explicit type.required: Mark as required.rest: Capture remaining positional arguments as an array.raw: Capture ALL remaining arguments (including flags) without parsing them (proxy mode).
@subCommand(Class, options?)- Associate a property with a subcommand class.@validate(predicate, message)- Add custom inline validation.@addValidator(fn)- Building block for reusable validators.
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"})classExampleextendsArgs{
@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"})classProxyextendsArgs{
@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