Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/basedwon/arrrg
https://github.com/basedwon/arrrg
Last synced: 1 day ago
JSON representation
- Host: GitHub
- URL: https://github.com/basedwon/arrrg
- Owner: basedwon
- License: mit
- Created: 2022-04-16T04:18:33.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-04-28T04:44:12.000Z (over 2 years ago)
- Last Synced: 2024-10-04T16:17:54.274Z (about 1 month ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# Arrrg
`arrrg` is a simple CLI argument parser.
## Installation
```sh
npm install arrrg
```## Usage
`arrrg(definition, [defaults], [examples], [argv])`
## Example
```js
const Arrrg = require('arrrg')const definition = [
{ name: 'servn', type: String, command: true, default: '.', swap: 'docroot' },
{ name: 'host', type: String, help: 'define the host', default: 'localhost' },
{ name: 'file', type: String, aliases: ['f'], help: 'define the file', default: 'main.js' },
{ name: 'port', type: Number, aliases: ['p'], help: 'define the port', default: 8080 },
{ name: 'cert', help: 'define the TLS cert' },
{ name: 'help', type: Boolean, aliases: ['h', 'help'], help: 'show this dialog' },
]
const defaults = {
host: 'localhost',
file: 'main.js'
}
const examples = [
`servn`,
`servn -p 3000`,
`servn ~/project --host example.com --file index.js`,
]
const argv = ['.', '--cert', 'localhost-key.pem', '--help']
const opts = Arrrg(definition, defaults, examples, argv)console.log(opts)
/*
{
_: [],
servn: '.',
cert: 'localhost-key.pem',
help: true,
host: 'localhost',
file: 'main.js',
port: 8080
}
*/if (opts.help)
return opts.showHelp() // showHelp result:
/*
ServnUsage: servn ...args [options]
Options:
--host define the host
-f, --file define the file
-p, --port define the port
--cert define the TLS cert
-h, --help show this dialogExamples:
servn
servn -p 3000
servn ~/project --host example.com --file index.js
*/
```