console-app/README.md

65 lines
1.7 KiB
Markdown
Raw Normal View History

2020-05-15 16:53:45 +02:00
# @sapphirecode/console-app
version: 2.1.x
2020-05-15 16:53:45 +02:00
2020-06-12 14:34:45 +02:00
read parameters from env, config files, console args or interactively
2020-05-15 16:53:45 +02:00
## Installation
npm:
> npm i --save @sapphirecode/console-app
yarn:
> yarn add @sapphirecode/console-app
## Usage
```js
const {
ArrayOption, // arrays made out of numbers, strings and booleans
BooleanOption,
FileOption, // paths that exist and are a file
FolderOption, // paths that exist and are a folder
NumberOption, // integer and float values
IntegerOption, // only integer values
PathOption, // paths that exist in the file system
StringOption,
} = require('@sapphirecode/console-app');
2020-05-15 16:53:45 +02:00
2020-06-12 14:34:45 +02:00
const input = await new BooleanOption({
name: 'foo', // option name used in configs and console arguments
// optional settings:
default: false, // default value
sources: {
configs: [], // config files to read from. none by default
interactive: true, // use interactive prompts
console: true // read from console arguments
// environment is always on if the 'env' option below is specified
},
alias: 'f', // shorthand console argument name
env: 'foo_env', // name of the environment variable to read from
message: 'input foo', // message to display in interactive prompt
error: 'failed to read foo', // message to display when input was invalid
error_callback: (opt, val, err)=>{...}, // function to call when an option value could not be read
exit_on_interrupt: true, // exit program when user cancels the interactive prompt
}).parse();
```
2020-05-15 16:53:45 +02:00
2020-05-27 09:55:52 +02:00
config files can import other config files with #include. example:
```json
#include base.json
{
"foo": "bar"
}
```
2020-05-27 17:39:32 +02:00
config files are parsed using [hjson](https://github.com/hjson/hjson-js)
2020-05-15 16:53:45 +02:00
## License
MIT © Timo Hocker <timo@scode.ovh>