From 3766958b202e6a9957602e9c7a15a44a1f87a3c1 Mon Sep 17 00:00:00 2001 From: Timo Hocker Date: Mon, 18 May 2020 19:18:02 +0200 Subject: [PATCH] config source --- Jenkinsfile | 2 +- README.md | 5 +++-- lib/InteractiveOptions.ts | 21 ++++++++++++------ lib/Sources/ConfigSource.ts | 43 +++++++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 10 deletions(-) create mode 100644 lib/Sources/ConfigSource.ts diff --git a/Jenkinsfile b/Jenkinsfile index 0166a7b..e7ce23a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,7 +5,7 @@ pipeline { VERSION = VersionNumber([ versionNumberString: '${BUILDS_ALL_TIME}', - versionPrefix: '1.2.', + versionPrefix: '1.3.', worstResultForIncrement: 'SUCCESS' ]) } diff --git a/README.md b/README.md index 85839ea..73cf658 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # @sapphirecode/console-app -version: 1.2.x +version: 1.3.x read parameters from env, console args or interactively @@ -54,13 +54,14 @@ the console reader automatically adds the options --help (-h) and --quiet (-q) parameters are specified the reader can also be constructed with additional options that specify which -sources should be used. It reads from all by default +sources should be used. It reads from all, except config files by default ```js const reader = new InteractiveOptions([], { args: true, env: true, interactive: true, + configs: ['json files to search for options'] }); ``` diff --git a/lib/InteractiveOptions.ts b/lib/InteractiveOptions.ts index 44b9506..762a95d 100644 --- a/lib/InteractiveOptions.ts +++ b/lib/InteractiveOptions.ts @@ -12,6 +12,7 @@ import { OptionType } from './OptionType'; import { OptionSource } from './Sources/OptionSource'; import { EnvSource } from './Sources/EnvSource'; import { ArgSource } from './Sources/ArgSource'; +import { ConfigSource } from './Sources/ConfigSource'; import { InteractiveSource } from './Sources/InteractiveSource'; import { Option, OptionProcess } from './Option'; @@ -26,9 +27,10 @@ const types: Record = { }; interface SourceConfig { - env: boolean; - args: boolean; - interactive: boolean; + env?: boolean; + args?: boolean; + interactive?: boolean; + configs?: string[]; } export class InteractiveOptions extends Persistent { @@ -38,7 +40,7 @@ export class InteractiveOptions extends Persistent { public constructor ( options: Array