Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jaredkrinke/flags_usage
Adds "--help" to Deno's std/flags module
https://github.com/jaredkrinke/flags_usage
deno flags help usage
Last synced: about 2 months ago
JSON representation
Adds "--help" to Deno's std/flags module
- Host: GitHub
- URL: https://github.com/jaredkrinke/flags_usage
- Owner: jaredkrinke
- License: mit-0
- Created: 2021-11-15T02:05:50.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2021-12-21T04:46:13.000Z (about 3 years ago)
- Last Synced: 2024-10-16T21:41:31.015Z (3 months ago)
- Topics: deno, flags, help, usage
- Language: TypeScript
- Homepage:
- Size: 9.77 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# flags_usage
Adds "--help" to Deno's std/flags module, for printing out command line usage/option information.# Example
main.ts:
```typescript
import { processFlags } from "https://deno.land/x/flags_usage/mod.ts";const options = {
preamble: "Usage: my-tool ", // New: Optional preamble for describing non-flag/positional arguments
description: { output: "Output directory" }, // New: Description of flag
argument: { output: "dir" }, // New: "" in the output below
string: [ "output" ],
default: { output: "out" },
};// `processFlags` parses normally, except it will print usage and exit on `--help`
const { output } = processFlags(Deno.args, options);
```Output:
```
$ deno run main.ts --help
Usage: my-toolOptions:
--output Output directory (default: "out")
-h, -?, --help Display usage information
```Note that `parseFlags`, `logUsage`, etc. (see API) can be used if automatically exiting on `--help` is not desirable.
# API
## Options
All `options` arguments follow std/flags's interface, with the following new, *optional* properties:* `preamble`: An optional string to print out before flag information on `--help`
* `description`: An object mapping flags to descriptions that will be displayed on `--help`
* `argument`: An object mapping flags to names for their arguments to be displayed on `--help` (e.g. mapping `out` to `path` will display `--out ...` instead of the generic `--out ` for string arguments)## `processFlags(Deno.args, options)`
Parse options as usual, but add `--help` and automatically print usage and exit if `--help`/`-h`/`-?` are specified.## `parseFlags(Deno.args, options)`
Parse options as usual, with `--help`/`-h`/`-?` added as a Boolean flag (note: with this function, the caller must decide what to do if the `help` flag is set to true--use `processFlags` to automatically print usage and exit).## `formatUsage(options)`
Format usage information as a string.## `logUsage(options)`
Format usage information and print to the console.