Timo Hocker 3b140a4b11 update-scanner: automatic update
@sapphirecode/eslint-config-ts: 1.1.7 ==> 1.1.9 minor
@sapphirecode/modelling: 1.0.37 ==> 1.0.38 minor
@types/fs-extra: 9.0.0 ==> 9.0.1 minor
eslint: 7.0.0 ==> 7.1.0 minor
typescript: 3.9.2 ==> 3.9.3 minor
2020-05-23 18:20:47 +02:00
2020-05-22 11:50:07 +02:00
2020-05-15 16:53:45 +02:00
2020-05-05 11:56:36 +02:00
2020-05-15 16:53:45 +02:00
2020-05-05 11:56:36 +02:00
2020-05-05 13:32:40 +02:00
2020-05-22 11:50:07 +02:00
2020-05-15 16:53:45 +02:00
2020-05-22 11:50:07 +02:00
2020-05-05 13:32:40 +02:00
2020-05-18 10:28:50 +02:00
2020-05-22 11:50:07 +02:00
2020-05-18 10:24:41 +02:00
fix
2020-05-06 07:32:51 +02:00
2020-05-23 18:20:47 +02:00

@sapphirecode/console-app

version: 1.4.x

read parameters from env, console args or interactively

Installation

npm:

npm i --save @sapphirecode/console-app

yarn:

yarn add @sapphirecode/console-app

Usage

const {InteractiveOptions} = require('@sapphirecode/console-app');

const reader = new InteractiveOptions([
  {
    name: 'foo', // name of the option
    type: 'boolean', // data type
    required: true, // require option to be specified (optional)
    default: false, // default value (optional)
    alias: 'f', // shorthand alias in the console (optional)
    env: 'fooenv', // environment variable to read from (optional)
    description: 'the switch foo', // description in the help page (optional)
    message: 'should foo be true?', // message when asking interactively (optional)
    preset: [] // preset choices for string and path types (optional)
  },
]);

const result = await reader.parse();
console.log(result.foo);

available data types:

  • string
  • number
  • boolean
  • path: expects a path that exists
  • file: expects a path that exists and is a file
  • folder: expects a path that exists and is a folder
  • array: arrays made out of strings, numbers and booleans

the console reader automatically adds the options --help (-h) and --quiet (-q)

  • help: shows the yargs help screen
  • quiet: prevents interactive queries and throws an error when not all required parameters are specified

the reader can also be constructed with additional options that specify which sources should be used. It reads from all, except config files by default

the option exit_on_interrupt determines whether an error should be thrown or the process should exit when the user presses control + c in an interactive prompt.

const reader = new InteractiveOptions([], {
  args: true,
  env: true,
  interactive: true,
  configs: ['json files to search for options'],
  exit_on_interrupt: true
});

License

MIT © Timo Hocker timo@scode.ovh

Description
No description provided
Readme 409 KiB
Languages
TypeScript 96.5%
JavaScript 3.5%