https://github.com/timreichen/program
command-line interface for deno programs.
https://github.com/timreichen/program
cli deno
Last synced: about 1 month ago
JSON representation
command-line interface for deno programs.
- Host: GitHub
- URL: https://github.com/timreichen/program
- Owner: timreichen
- License: mit
- Created: 2020-07-31T12:22:46.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-09-17T19:19:31.000Z (almost 6 years ago)
- Last Synced: 2025-05-16T00:22:52.727Z (about 1 year ago)
- Topics: cli, deno
- Language: TypeScript
- Homepage:
- Size: 26.4 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Program
Simple command-line interface for deno programs.
## Usage
```ts
// cli.ts
import { Program } from "https://deno.land/x/program/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)
```
```sh
deno run cli.ts log hello world
```
Output:
```sh
{ _: [ "hello", "world" ] }
```
## Help
Program generates help for program and subcommands automatically.
### Program
```sh
deno run cli.ts --help
```
Output:
```sh
logger 1.0.1
program that logs
USAGE:
logger [OPTIONS] [SUBCOMMAND]
OPTIONS:
-h, --help Prints help information
SUBCOMMANDS:
log logs parsed arguments
```
### Subcommand
```sh
deno run test.ts log --help
```
Output:
```sh
log-logger
logs parsed arguments
USAGE:
log logger [OPTIONS] [source_file]...
OPTIONS:
-q, --quiet Suppress diagnostic output
ARGS:
[source_file]...
```