# nopt-usage

> This module generates a usage string for nopt options. It's based on [this](https://github.com/npm/nopt/pull/13) PR from Filirom1.

Latest version **0.1.0** (published 2014-01-12) · MIT license · 56.7K weekly downloads

## Install

```sh
npm install nopt-usage
pnpm add nopt-usage
yarn add nopt-usage
bun add nopt-usage
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2014-01-12 |
| First published | 2014-01-12 |
| Weekly downloads | 56.7K |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | zaach |
| Keywords | nopt, option, parser, help, usage |

## Links

- npm: https://www.npmjs.com/package/nopt-usage
- npm.io page: https://npm.io/package/nopt-usage

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2014-01-12

## README

# Show usage

This module generates a usage string for nopt options. It's based on [this](https://github.com/npm/nopt/pull/13) PR from Filirom1.

```
var noptUsage = require('nopt-usage');
noptUsage(knownOpts, shortHands, description1, description2, ...)
```
## install

    npm install nopt-usage

## example

You could pass as many description objects as you want. Take a look at the following example to understand how it could be used.

```
#!/usr/bin/env node

var nopt = require("nopt")
  , noptUsage = require("nopt-usage")
  , Stream = require("stream").Stream
  , path = require("path")
  , knownOpts = { "foo" : [String, null]
                , "bar" : [Stream, Number]
                , "baz" : path
                , "bloo" : [ "big", "medium", "small" ]
                , "flag" : Boolean
                , "pick" : Boolean
                }
  , shortHands = { "foofoo" : ["--foo", "Mr. Foo"]
                 , "b7" : ["--bar", "7"]
                 , "m" : ["--bloo", "medium"]
                 , "p" : ["--pick"]
                 , "f" : ["--flag", "true"]
                 , "g" : ["--flag"]
                 , "s" : "--flag"
                 }
  , description = { "foo" : "Something really foooooooo"
                  , "bar" : "A bar thing"
                  , "baz" : "More or less baz"
                  , "flag" : "Flag it as well"
                  , "pick" : "Or pick something"
                  }
  , defaults = { "foo" : null
               , "bar" : 42
               , "baz" : "/etc/passwd"
               , "bloo" : "small"
               , "pick" : false
               }
             // everything is optional.
             // knownOpts and shorthands default to {}
             // arg list defaults to process.argv
             // slice defaults to 2
  , parsed = nopt(knownOpts, shortHands, process.argv, 2)
  , usage = noptUsage(knownOpts, shortHands, description, defaults)

console.log('Usage: ')
console.log(usage)
```

The output is:

```
Usage:
    --foo, -foofoo        Something really foooooooo    null           
    --bar, -b7            A bar thing                   42             
    --baz                 More or less baz              /etc/passwd    
    --bloo, -m                                          small          
    --flag, -f, -g, -s    Flag it as well                              
    --pick, -p            Or pick something             false          
```

---
_Source: https://npm.io/package/nopt-usage · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
