Repository
Current version released
4 years ago
Dependencies
std
Program
command-line interface for deno programs.
Usage
// cli.ts
import { Program } from "https://raw.githubusercontent.com/timreichen/program/master/mod.ts"
function log(args: any) {
if (args.quiet) { return }
console.log(args)
}
const program = new Program({ name: "logger", description: "program that logs", version: "1.0.1" })
program
.command({ name: "log", description: "logs parsed arguments", fn: log })
.option({ name: "quiet", alias: "q", description: "Suppress diagnostic output" })
.argument({ name: "source_file", multiple: true, optional: true })
program.parse(Deno.args)
deno run cli.ts log hello world
Output:
{ _: [ "hello", "world" ] }
Help
Program generates help for program and subcommands automatically.
Program
deno run cli.ts --help
Output:
logger 1.0.1
program that logs
USAGE:
logger [OPTIONS] [SUBCOMMAND]
OPTIONS:
-h, --help Prints help information
SUBCOMMANDS:
log logs parsed arguments
Subcommand
deno run test.ts log --help
Output:
log-logger
logs parsed arguments
USAGE:
log logger [OPTIONS] [source_file]...
OPTIONS:
-q, --quiet Suppress diagnostic output
ARGS:
[source_file]...