From 3f0b9fad7910cd16d8a5a641e3e29ef264243507 Mon Sep 17 00:00:00 2001 From: Timo Hocker Date: Tue, 9 Jun 2020 13:13:27 +0200 Subject: [PATCH] starting to split options by type --- lib/{Types => }/ErrorCallback.ts | 0 lib/InteractiveOptions.ts | 108 ------------------ lib/Option.ts | 29 +++-- lib/OptionType.ts | 16 --- lib/Options/ArrayOption.ts | 0 lib/Options/BaseOption.ts | 45 ++++++++ lib/Options/BooleanOption.ts | 0 lib/Options/FileOption.ts | 0 lib/Options/FolderOption.ts | 0 lib/Options/NumberOption.ts | 0 lib/Options/PathOption.ts | 0 lib/Options/StringOption.ts | 14 +++ lib/Sources/ConfigSource.ts | 2 +- lib/Sources/InteractiveSource.ts | 2 +- lib/Sources/OptionSource.ts | 8 +- lib/TypeRegister.ts | 12 ++ lib/{Types => TypeValidation}/PathType.ts | 0 .../TypeValidation.ts | 0 test/PathType.ts | 2 +- test/TypeValidation.ts | 2 +- 20 files changed, 96 insertions(+), 144 deletions(-) rename lib/{Types => }/ErrorCallback.ts (100%) delete mode 100644 lib/InteractiveOptions.ts delete mode 100644 lib/OptionType.ts create mode 100644 lib/Options/ArrayOption.ts create mode 100644 lib/Options/BaseOption.ts create mode 100644 lib/Options/BooleanOption.ts create mode 100644 lib/Options/FileOption.ts create mode 100644 lib/Options/FolderOption.ts create mode 100644 lib/Options/NumberOption.ts create mode 100644 lib/Options/PathOption.ts create mode 100644 lib/Options/StringOption.ts create mode 100644 lib/TypeRegister.ts rename lib/{Types => TypeValidation}/PathType.ts (100%) rename lib/{Types => TypeValidation}/TypeValidation.ts (100%) diff --git a/lib/Types/ErrorCallback.ts b/lib/ErrorCallback.ts similarity index 100% rename from lib/Types/ErrorCallback.ts rename to lib/ErrorCallback.ts diff --git a/lib/InteractiveOptions.ts b/lib/InteractiveOptions.ts deleted file mode 100644 index 789af42..0000000 --- a/lib/InteractiveOptions.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (C) Sapphirecode - All Rights Reserved - * This file is part of console-app which is released under MIT. - * See file 'LICENSE' for full license details. - * Created by Timo Hocker , May 2020 - */ - -import { Persistent } from '@sapphirecode/modelling'; -import { TypeValidation } from './Types/TypeValidation'; -import { PathType } from './Types/PathType'; -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'; -import { ErrorCallback } from './Types/ErrorCallback'; - -const types: Record = { - string: new TypeValidation ('string'), - number: new TypeValidation ('number'), - boolean: new TypeValidation ('boolean'), - file: new PathType ('file'), - folder: new PathType ('folder'), - path: new PathType ('path'), - array: new TypeValidation ('array') -}; - -interface SourceConfig { - env?: boolean; - args?: boolean; - interactive?: boolean; - configs?: string[]; - exit_on_interrupt?: boolean; - error_callback?: ErrorCallback; -} - -export class InteractiveOptions extends Persistent { - protected options: Array; - protected quiet = false; - protected sources: OptionSource[] = []; - - public constructor ( - options: Array