@flowscripter/dynamic-cli-framework 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/check-bun-dependencies.yml +9 -0
- package/.github/workflows/lint-pr-message.yml +11 -0
- package/.github/workflows/release-bun-library.yml +8 -0
- package/.github/workflows/validate-bun-library-pr.yml +8 -0
- package/LICENSE +21 -0
- package/README.md +1475 -0
- package/bun.lock +63 -0
- package/index.ts +89 -0
- package/package.json +23 -0
- package/src/api/CLI.ts +17 -0
- package/src/api/CLIConfig.ts +19 -0
- package/src/api/Context.ts +25 -0
- package/src/api/RunResult.ts +142 -0
- package/src/api/argument/Argument.ts +36 -0
- package/src/api/argument/ArgumentValueTypes.ts +87 -0
- package/src/api/argument/ComplexOption.ts +31 -0
- package/src/api/argument/GlobalCommandArgument.ts +17 -0
- package/src/api/argument/Option.ts +32 -0
- package/src/api/argument/Positional.ts +27 -0
- package/src/api/argument/SubCommandArgument.ts +20 -0
- package/src/api/command/Command.ts +22 -0
- package/src/api/command/GlobalCommand.ts +33 -0
- package/src/api/command/GlobalModifierCommand.ts +12 -0
- package/src/api/command/GroupCommand.ts +20 -0
- package/src/api/command/SubCommand.ts +41 -0
- package/src/api/command/UsageExample.ts +21 -0
- package/src/api/service/ServiceProvider.ts +52 -0
- package/src/api/service/core/AsciiBannerGeneratorService.ts +35 -0
- package/src/api/service/core/KeyValueService.ts +28 -0
- package/src/api/service/core/PrinterService.ts +266 -0
- package/src/api/service/core/ShutdownService.ts +12 -0
- package/src/api/service/core/SyntaxHighlighterService.ts +42 -0
- package/src/cli/BaseCLI.ts +312 -0
- package/src/cli/DefaultRuntimeCLI.ts +54 -0
- package/src/command/MultiCommandCliHelpCommand.ts +394 -0
- package/src/command/SingleCommandCliHelpCommand.ts +183 -0
- package/src/command/UsageCommand.ts +35 -0
- package/src/command/VersionCommand.ts +22 -0
- package/src/launcher.ts +127 -0
- package/src/runtime/DefaultContext.ts +32 -0
- package/src/runtime/argument/ArgumentTypeGuards.ts +8 -0
- package/src/runtime/command/CommandTypeGuards.ts +30 -0
- package/src/runtime/command/CommandValidator.ts +549 -0
- package/src/runtime/parser.ts +219 -0
- package/src/runtime/registry/CommandRegistry.ts +121 -0
- package/src/runtime/registry/DefaultCommandRegistry.ts +318 -0
- package/src/runtime/registry/DefaultServiceProviderRegistry.ts +26 -0
- package/src/runtime/registry/ServiceProviderRegistry.ts +11 -0
- package/src/runtime/runner.ts +697 -0
- package/src/runtime/scanner.ts +417 -0
- package/src/runtime/values/ValuePopulationResult.ts +41 -0
- package/src/runtime/values/argumentValueMerge.ts +201 -0
- package/src/runtime/values/argumentValueValidation.ts +610 -0
- package/src/runtime/values/globalCommandValuePopulation.ts +96 -0
- package/src/runtime/values/subCommandValuePopulation.ts +680 -0
- package/src/service/asciiBannerGenerator/AsciiBannerGeneratorServiceProvider.ts +45 -0
- package/src/service/asciiBannerGenerator/DefaultAsciiBannerGeneratorService.ts +38 -0
- package/src/service/asciiBannerGenerator/standard.flf.json +3 -0
- package/src/service/banner/BannerServiceProvider.ts +99 -0
- package/src/service/banner/command/NoBannerCommand.ts +42 -0
- package/src/service/configuration/ConfigurationServiceProvider.ts +571 -0
- package/src/service/configuration/DefaultKeyValueService.ts +60 -0
- package/src/service/configuration/command/ConfigCommand.ts +43 -0
- package/src/service/configuration/command/DumpConfigCommand.ts +47 -0
- package/src/service/printer/DefaultPrinterService.ts +256 -0
- package/src/service/printer/PrinterServiceProvider.ts +61 -0
- package/src/service/printer/command/DarkModeCommand.ts +43 -0
- package/src/service/printer/command/LogLevelCommand.ts +68 -0
- package/src/service/printer/command/NoColorCommand.ts +43 -0
- package/src/service/printer/terminal/Ansi.ts +10 -0
- package/src/service/printer/terminal/Color.ts +14 -0
- package/src/service/printer/terminal/Progress.ts +373 -0
- package/src/service/printer/terminal/Spinner.ts +100 -0
- package/src/service/printer/terminal/Styler.ts +5 -0
- package/src/service/printer/terminal/Terminal.ts +8 -0
- package/src/service/printer/terminal/Theme.ts +34 -0
- package/src/service/printer/terminal/TtyStyler.ts +39 -0
- package/src/service/printer/terminal/TtyTerminal.ts +65 -0
- package/src/service/shutdown/DefaultShutdownService.ts +9 -0
- package/src/service/shutdown/ShutdownServiceProvider.ts +55 -0
- package/src/service/syntaxHighlighter/DefaultSyntaxHighlighterService.ts +52 -0
- package/src/service/syntaxHighlighter/SyntaxHighlighterServiceProvider.ts +51 -0
- package/src/util/configHelper.ts +95 -0
- package/src/util/envVarHelper.ts +338 -0
- package/src/util/helpHelper.ts +751 -0
- package/src/util/logger.ts +84 -0
- package/src/util/runnerHelper.ts +112 -0
- package/tests/cli/BaseCLI.test.ts +344 -0
- package/tests/command/MultiCommandCliHelpCommand.test.ts +650 -0
- package/tests/command/SingleCommandCliHelpCommand.test.ts +384 -0
- package/tests/command/UsageCommand.test.ts +53 -0
- package/tests/command/VersionCommand.test.ts +36 -0
- package/tests/fixtures/CLIConfig.ts +9 -0
- package/tests/fixtures/Command.ts +229 -0
- package/tests/fixtures/CommandRegistry.ts +8 -0
- package/tests/fixtures/ConfigurationServiceProvider.ts +28 -0
- package/tests/fixtures/Context.ts +33 -0
- package/tests/fixtures/ServiceProviderRegistry.ts +16 -0
- package/tests/fixtures/StreamString.ts +37 -0
- package/tests/fixtures/util.ts +41 -0
- package/tests/runtime/DefaultContext.test.ts +20 -0
- package/tests/runtime/argument/ArgumentTypeGuards.test.ts +49 -0
- package/tests/runtime/command/CommandTypeGuards.test.ts +43 -0
- package/tests/runtime/command/CommandValidator.test.ts +816 -0
- package/tests/runtime/parser.test.ts +766 -0
- package/tests/runtime/registry/DefaultCommandRegistry.test.ts +166 -0
- package/tests/runtime/registry/DefaultServiceProviderRegistry.test.ts +42 -0
- package/tests/runtime/runner.test.ts +1298 -0
- package/tests/runtime/scanner.test.ts +1113 -0
- package/tests/runtime/values/argumentValueMerge.test.ts +314 -0
- package/tests/runtime/values/argumentValueValidation.test.ts +1020 -0
- package/tests/runtime/values/globalCommandValuePopulation.test.ts +662 -0
- package/tests/runtime/values/subCommandValuePopulation.test.ts +2658 -0
- package/tests/service/asciiBannerGenerator/AsciiBannerGeneratorServiceProvider.test.ts +22 -0
- package/tests/service/asciiBannerGenerator/DefaultAsciiBannerGeneratorService.test.ts +70 -0
- package/tests/service/asciiBannerGenerator/__snapshots__/DefaultAsciiBannerGeneratorService.test.ts.snap +22 -0
- package/tests/service/asciiBannerGenerator/small.flf.json +3 -0
- package/tests/service/configuration/ConfigurationServiceProvider.test.ts +249 -0
- package/tests/service/configuration/DefaultKeyValueService.test.ts +65 -0
- package/tests/service/launchBanner/BannerServiceProvider.test.ts +49 -0
- package/tests/service/launchBanner/__snapshots__/BannerServiceProvider.test.ts.snap +3 -0
- package/tests/service/launchBanner/command/NoBannerCommand.test.ts +21 -0
- package/tests/service/printer/DefaultPrinterService.test.ts +409 -0
- package/tests/service/printer/PrinterServiceProvider.test.ts +29 -0
- package/tests/service/printer/command/LogLevelCommand.test.ts +58 -0
- package/tests/service/printer/terminal/Progress.test.ts +40 -0
- package/tests/service/printer/terminal/Spinner.test.ts +57 -0
- package/tests/service/shutdown/ShutdownServiceProvider.test.ts +13 -0
- package/tests/service/syntaxHighlighter/DefaultSyntaxHighlighterService.test.ts +123 -0
- package/tests/service/syntaxHighlighter/SyntaxHighlighterServiceProvider.test.ts +41 -0
- package/tests/util/configHelper.test.ts +275 -0
- package/tests/util/envVarHelper.test.ts +318 -0
- package/tests/util/logger.test.ts +10 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type Command from "./Command.ts";
|
|
2
|
+
import type GlobalCommandArgument from "../argument/GlobalCommandArgument.ts";
|
|
3
|
+
import type Context from "../Context.ts";
|
|
4
|
+
import type { ArgumentSingleValueType } from "../argument/ArgumentValueTypes.ts";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Interface for a global command.
|
|
8
|
+
*/
|
|
9
|
+
export default interface GlobalCommand extends Command {
|
|
10
|
+
/**
|
|
11
|
+
* Optional short alias for the global command.
|
|
12
|
+
*
|
|
13
|
+
* Must consist of a single alphanumeric non-whitespace ASCII character.
|
|
14
|
+
*/
|
|
15
|
+
readonly shortAlias?: string;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Optional {@link GlobalCommandArgument} for the command.
|
|
19
|
+
*/
|
|
20
|
+
readonly argument?: GlobalCommandArgument;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Execute the command.
|
|
24
|
+
*
|
|
25
|
+
* @param context the {@link Context} in which to execute the command.
|
|
26
|
+
* @param argumentValue optional argument value for the command. This will be populated unless
|
|
27
|
+
* the command's {@link GlobalCommandArgument} is optional and the argument value was not provided.
|
|
28
|
+
*/
|
|
29
|
+
execute(
|
|
30
|
+
context: Context,
|
|
31
|
+
argumentValue?: ArgumentSingleValueType,
|
|
32
|
+
): Promise<void>;
|
|
33
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type GlobalCommand from "./GlobalCommand.ts";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Interface for a global modifier command.
|
|
5
|
+
*/
|
|
6
|
+
export default interface GlobalModifierCommand extends GlobalCommand {
|
|
7
|
+
/**
|
|
8
|
+
* Used to determine the order in which multiple global modifier command instances
|
|
9
|
+
* parsed from the provided arguments will be executed. Higher values will execute before lower values.
|
|
10
|
+
*/
|
|
11
|
+
readonly executePriority: number;
|
|
12
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type SubCommand from "./SubCommand.ts";
|
|
2
|
+
import type Command from "./Command.ts";
|
|
3
|
+
import type Context from "../Context.ts";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Interface for a group command.
|
|
7
|
+
*/
|
|
8
|
+
export default interface GroupCommand extends Command {
|
|
9
|
+
/**
|
|
10
|
+
* Array of {@link SubCommand} instances for this group command. Must contain at least one sub-command.
|
|
11
|
+
*/
|
|
12
|
+
readonly memberSubCommands: ReadonlyArray<SubCommand>;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Execute the command.
|
|
16
|
+
*
|
|
17
|
+
* @param context the {@link Context} in which to execute the command.
|
|
18
|
+
*/
|
|
19
|
+
execute(context: Context): Promise<void>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type Command from "./Command.ts";
|
|
2
|
+
import type Option from "../argument/Option.ts";
|
|
3
|
+
import type Positional from "../argument/Positional.ts";
|
|
4
|
+
import type UsageExample from "./UsageExample.ts";
|
|
5
|
+
import type ComplexOption from "../argument/ComplexOption.ts";
|
|
6
|
+
import type { ArgumentValues } from "../argument/ArgumentValueTypes.ts";
|
|
7
|
+
import type Context from "../Context.ts";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Interface for a sub-command.
|
|
11
|
+
*/
|
|
12
|
+
export default interface SubCommand extends Command {
|
|
13
|
+
/**
|
|
14
|
+
* {@link Option} or {@link ComplexOption} argument definitions for the sub-command.
|
|
15
|
+
*/
|
|
16
|
+
readonly options: ReadonlyArray<Option | ComplexOption>;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* {@link Positional} argument definitions for the sub-command.
|
|
20
|
+
*/
|
|
21
|
+
readonly positionals: ReadonlyArray<Positional>;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Optional grouping topic of the command to structuring of help output.
|
|
25
|
+
*/
|
|
26
|
+
readonly helpTopic?: string;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Optional usage examples for the command to support help output.
|
|
30
|
+
*/
|
|
31
|
+
readonly usageExamples?: ReadonlyArray<UsageExample>;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Execute the command.
|
|
35
|
+
*
|
|
36
|
+
* @param context the {@link Context} in which to execute the command.
|
|
37
|
+
* @param argumentValues the argument values for the command. This may be empty if
|
|
38
|
+
* the command's {@link Option} and {@link Positional} instances are all optional and no argument values were provided.
|
|
39
|
+
*/
|
|
40
|
+
execute(context: Context, argumentValues: ArgumentValues): Promise<void>;
|
|
41
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A usage example for a {@link SubCommand} to be used in help output.
|
|
3
|
+
*/
|
|
4
|
+
export default interface UsageExample {
|
|
5
|
+
/**
|
|
6
|
+
* The example arguments used to generate an example invocation.
|
|
7
|
+
*
|
|
8
|
+
* This should not include the CLI or command name.
|
|
9
|
+
*/
|
|
10
|
+
readonly exampleArguments: string;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Optional description of the command example.
|
|
14
|
+
*/
|
|
15
|
+
readonly description?: string;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Optional output result of executing the example command.
|
|
19
|
+
*/
|
|
20
|
+
readonly output?: ReadonlyArray<string>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type Command from "../command/Command.ts";
|
|
2
|
+
import type Context from "../Context.ts";
|
|
3
|
+
import type CLIConfig from "../CLIConfig.ts";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Information regarding a service instance provided by a {@link ServiceProvider}.
|
|
7
|
+
*/
|
|
8
|
+
export interface ServiceInfo {
|
|
9
|
+
/**
|
|
10
|
+
* Optional, a service in the {@link Context}.
|
|
11
|
+
*/
|
|
12
|
+
readonly service?: unknown;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Zero or more {@link Command} instances related to the service which should be registered.
|
|
16
|
+
*/
|
|
17
|
+
readonly commands: ReadonlyArray<Command>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Interface allowing services to be provided to the CLI.
|
|
22
|
+
*/
|
|
23
|
+
export interface ServiceProvider {
|
|
24
|
+
/**
|
|
25
|
+
* The ID which identifies the service provided.
|
|
26
|
+
*/
|
|
27
|
+
readonly serviceId: string;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Used to determine the order in which multiple service instances will be initialised. Higher values
|
|
31
|
+
* will be initialised before lower values.
|
|
32
|
+
*/
|
|
33
|
+
readonly servicePriority: number;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Return {@link ServiceInfo} containing the service and any commands which should be registered in the CLI.
|
|
37
|
+
*
|
|
38
|
+
* @param cliConfig the {@link CLIConfig} for the CLI.
|
|
39
|
+
*/
|
|
40
|
+
provide(cliConfig: CLIConfig): Promise<ServiceInfo>;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Initialise the service. This will be invoked AFTER any {@link GlobalModifierCommand} provided in the
|
|
44
|
+
* {@link ServiceInfo} have been invoked (if specified as CLI arguments or CLI configuration).
|
|
45
|
+
*
|
|
46
|
+
* NOTE: Other services within the provided context will only have been initialised if they have a higher
|
|
47
|
+
* {@link servicePriority} value than the current service.
|
|
48
|
+
*
|
|
49
|
+
* @param context the {@link Context} in which the CLI is running.
|
|
50
|
+
*/
|
|
51
|
+
initService(context: Context): Promise<void>;
|
|
52
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export const ASCII_BANNER_GENERATOR_SERVICE_ID =
|
|
2
|
+
"@flowscripter/dynamic-cli-framework/ascii-banner-generator-service";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Service allowing a text string to be rendered using an ASCII banner [FIGlet](http://www.figlet.org) font.
|
|
6
|
+
*/
|
|
7
|
+
export default interface AsciiBannerGeneratorService {
|
|
8
|
+
/**
|
|
9
|
+
* Register a new font.
|
|
10
|
+
*
|
|
11
|
+
* The recommended way to load the font definition is to convert the font definition to a JSON string
|
|
12
|
+
* (replacing newlines with `\n`) and placing in a simple JSON file: `{ "font": "<figlet font definition>" }`.
|
|
13
|
+
* This can then be imported as follows:
|
|
14
|
+
*
|
|
15
|
+
* `import { font as myFont } from "./myfont.json" with { type: "json" };
|
|
16
|
+
*
|
|
17
|
+
* @param fontName the name used to refer to the font.
|
|
18
|
+
* @param fontDefinition the definition for the syntax conforming to the
|
|
19
|
+
* [FIGfont format](http://www.jave.de/figlet/figfont.html#creating).
|
|
20
|
+
*/
|
|
21
|
+
registerFont(fontName: string, fontDefinition: string): void;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Return the names of the currently registered fonts.
|
|
25
|
+
*/
|
|
26
|
+
getRegisteredFonts(): ReadonlyArray<string>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Generate an ASCII banner text for the message using the specified font.
|
|
30
|
+
*
|
|
31
|
+
* @param message the message to output.
|
|
32
|
+
* @param fontName the font to use.
|
|
33
|
+
*/
|
|
34
|
+
generate(message: string, fontName: string): Promise<string>;
|
|
35
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export const KEY_VALUE_SERVICE_ID =
|
|
2
|
+
"@flowscripter/dynamic-cli-framework/key-value-service";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Service providing keystore functionality for the CLI. The keystore data is scoped to the
|
|
6
|
+
* service or {@link Command} instances accessing this service via {@link Context.getServiceById}
|
|
7
|
+
*/
|
|
8
|
+
export default interface KeyValueService {
|
|
9
|
+
/**
|
|
10
|
+
* Get a value for a specified key in the keystore.
|
|
11
|
+
*/
|
|
12
|
+
getKey(key: string): string;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Set a value for a specified key in the keystore.
|
|
16
|
+
*/
|
|
17
|
+
setKey(key: string, value: string): void;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Check if a value for a specified key exists in the keystore.
|
|
21
|
+
*/
|
|
22
|
+
hasKey(key: string): boolean;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Delete the value for a specified key in the keystore.
|
|
26
|
+
*/
|
|
27
|
+
deleteKey(key: string): void;
|
|
28
|
+
}
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
export const PRINTER_SERVICE_ID =
|
|
2
|
+
"@flowscripter/dynamic-cli-framework/printer-service";
|
|
3
|
+
import { WritableStream } from "node:stream/web";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Enum of message importance level.
|
|
7
|
+
*/
|
|
8
|
+
export enum Level {
|
|
9
|
+
DEBUG = 0,
|
|
10
|
+
INFO = 1,
|
|
11
|
+
WARN = 2,
|
|
12
|
+
ERROR = 3,
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Enum of message icons.
|
|
17
|
+
*/
|
|
18
|
+
export enum Icon {
|
|
19
|
+
// Will be displayed in green if {@link Printer.colorEnabled} is `true`.
|
|
20
|
+
SUCCESS = 0,
|
|
21
|
+
// Will be displayed in red if {@link Printer.colorEnabled} is `true`.
|
|
22
|
+
FAILURE = 1,
|
|
23
|
+
// Will be displayed in yellow if {@link Printer.colorEnabled} is `true`.
|
|
24
|
+
ALERT = 2,
|
|
25
|
+
// Will be displayed in blue if {@link Printer.colorEnabled} is `true`.
|
|
26
|
+
INFORMATION = 3,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Service allowing a {@link Command} to output user messages to `stdout` and/or `stderr`.
|
|
31
|
+
*
|
|
32
|
+
* Output to `stdout` is via {@link print} whilst output to `stderr` is via a filtered logging mechanism
|
|
33
|
+
* using {@link debug}, {@link info}, {@link warn} and {@link error}.
|
|
34
|
+
*/
|
|
35
|
+
export default interface PrinterService {
|
|
36
|
+
/**
|
|
37
|
+
* Disable or enable color output for messages.
|
|
38
|
+
*/
|
|
39
|
+
colorEnabled: boolean;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Enable or disable dark mode. Default is disabled i.e. `false`.
|
|
43
|
+
*/
|
|
44
|
+
darkMode: boolean;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The WritableStream used for `stdout`. Can be accessed directly for output of binary data etc.
|
|
48
|
+
*/
|
|
49
|
+
stdoutWritable: WritableStream;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The WritableStream used for `stderr`. Can be accessed directly for output of binary data etc.
|
|
53
|
+
*/
|
|
54
|
+
stderrWritable: WritableStream;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Return the provided message so that the foreground is colored as primary content. This is the default
|
|
58
|
+
* calor applied. The actual color will depend on the value of {@link darkMode}.
|
|
59
|
+
* Has no effect if {@link colorEnabled} is `false`.
|
|
60
|
+
*/
|
|
61
|
+
primary(message: string): string;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Return the provided message so that the foreground is colored as secondary content.
|
|
65
|
+
* The actual color will depend on the value of {@link darkMode}.
|
|
66
|
+
* Has no effect if {@link colorEnabled} is `false`.
|
|
67
|
+
*/
|
|
68
|
+
secondary(message: string): string;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Return the provided message so that the foreground is colored as emphasised content.
|
|
72
|
+
* The actual color will depend on the value of {@link darkMode}.
|
|
73
|
+
* Has no effect if {@link colorEnabled} is `false`.
|
|
74
|
+
*/
|
|
75
|
+
emphasised(message: string): string;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Return the provided message so that the background is colored as selected content.
|
|
79
|
+
* The actual color will depend on the value of {@link darkMode}.
|
|
80
|
+
* Has no effect if {@link colorEnabled} is `false`.
|
|
81
|
+
*/
|
|
82
|
+
selected(message: string): string;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Return the provided message so that the text is displayed in italic.
|
|
86
|
+
*/
|
|
87
|
+
italic(message: string): string;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Return the provided message so that the foreground is yellow.
|
|
91
|
+
* Has no effect if {@link colorEnabled} is `false`.
|
|
92
|
+
*/
|
|
93
|
+
yellow(message: string): string;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Return the provided message so that the foreground is orange.
|
|
97
|
+
* Has no effect if {@link colorEnabled} is `false`.
|
|
98
|
+
*/
|
|
99
|
+
orange(message: string): string;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Return the provided message so that the foreground is red.
|
|
103
|
+
* Has no effect if {@link colorEnabled} is `false`.
|
|
104
|
+
*/
|
|
105
|
+
red(message: string): string;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Return the provided message so that the foreground is magenta.
|
|
109
|
+
* Has no effect if {@link colorEnabled} is `false`.
|
|
110
|
+
*/
|
|
111
|
+
magenta(message: string): string;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Return the provided message so that the foreground is violet.
|
|
115
|
+
* Has no effect if {@link colorEnabled} is `false`.
|
|
116
|
+
*/
|
|
117
|
+
violet(message: string): string;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Return the provided message so that the foreground is blue.
|
|
121
|
+
* Has no effect if {@link colorEnabled} is `false`.
|
|
122
|
+
*/
|
|
123
|
+
blue(message: string): string;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Return the provided message so that the foreground is cyan.
|
|
127
|
+
* Has no effect if {@link colorEnabled} is `false`.
|
|
128
|
+
*/
|
|
129
|
+
cyan(message: string): string;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Return the provided message so that it the foreground is green.
|
|
133
|
+
* Has no effect if {@link colorEnabled} is `false`.
|
|
134
|
+
*/
|
|
135
|
+
green(message: string): string;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Print a message on `stdout`.
|
|
139
|
+
* Will be displayed as primary content if {@link colorEnabled} is `true`.
|
|
140
|
+
*
|
|
141
|
+
* @param message the message to output.
|
|
142
|
+
* @param icon optional icon to display with the message.
|
|
143
|
+
*/
|
|
144
|
+
print(message: string, icon?: Icon): Promise<void>;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Print a {@link DEBUG} level message on `stderr`.
|
|
148
|
+
* Will be displayed as secondary content if {@link colorEnabled} is `true`.
|
|
149
|
+
*
|
|
150
|
+
* @param message the message to output.
|
|
151
|
+
* @param icon optional icon to display with the message.
|
|
152
|
+
*/
|
|
153
|
+
debug(message: string, icon?: Icon): Promise<void>;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Print an {@link INFO} level message on `stderr`.
|
|
157
|
+
* Will be displayed as primary content if {@link colorEnabled} is `true`.
|
|
158
|
+
*
|
|
159
|
+
* @param message the message to output.
|
|
160
|
+
* @param icon optional icon to display with the message.
|
|
161
|
+
*/
|
|
162
|
+
info(message: string, icon?: Icon): Promise<void>;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Print a {@link WARN} level message on `stderr`.
|
|
166
|
+
* Will be displayed as yellow content if {@link colorEnabled} is `true`.
|
|
167
|
+
*
|
|
168
|
+
* @param message the message to output.
|
|
169
|
+
* @param icon optional icon to display with the message.
|
|
170
|
+
*/
|
|
171
|
+
warn(message: string, icon?: Icon): Promise<void>;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Print an {@link ERROR} level message on `stderr`.
|
|
175
|
+
* Will be displayed as red content if {@link colorEnabled} is `true`.
|
|
176
|
+
*
|
|
177
|
+
* @param message the message to output.
|
|
178
|
+
* @param icon optional icon to display with the message.
|
|
179
|
+
*/
|
|
180
|
+
error(message: string, icon?: Icon): Promise<void>;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Set the output threshold {@link Level} for `stderr`.
|
|
184
|
+
*
|
|
185
|
+
* Default level is {@link INFO}.
|
|
186
|
+
*
|
|
187
|
+
* @param level any message below this level will be filtered from output,
|
|
188
|
+
*/
|
|
189
|
+
setLevel(level: Level): void;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Get the output threshold {@link Level} for `stderr`.
|
|
193
|
+
*/
|
|
194
|
+
getLevel(): Level;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Display the spinner on `stderr`.
|
|
198
|
+
*
|
|
199
|
+
* The spinner will be displayed as emphasised content and the message will
|
|
200
|
+
* be displayed as primary content if {@link colorEnabled} is `true`.
|
|
201
|
+
*
|
|
202
|
+
* NOTE: The spinner and message will be displayed at {@link INFO} level.
|
|
203
|
+
*
|
|
204
|
+
* NOTE: If the spinner is already displayed the message will be updated to that specified.
|
|
205
|
+
*
|
|
206
|
+
* NOTE: If any progress bars are currently displayed they will be hidden.
|
|
207
|
+
*
|
|
208
|
+
* @param message the message to output after the spinner.
|
|
209
|
+
*/
|
|
210
|
+
showSpinner(message: string): Promise<void>;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Hide the spinner.
|
|
214
|
+
*
|
|
215
|
+
* NOTE: Showing a progress bar will also hide the spinner.
|
|
216
|
+
*/
|
|
217
|
+
hideSpinner(): Promise<void>;
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Display a progress bar on `stderr`.
|
|
221
|
+
*
|
|
222
|
+
* The progress will be displayed in green if {@link colorEnabled} is `true`.
|
|
223
|
+
*
|
|
224
|
+
* NOTE: The progress bar and message will be displayed at {@link INFO} level.
|
|
225
|
+
*
|
|
226
|
+
* NOTE: If the spinner is currently displayed it will be hidden.
|
|
227
|
+
*
|
|
228
|
+
* @param units the units to display for progress indication e.g. 'MB' or 'Kb'.
|
|
229
|
+
* @param message an optional message for the progress bar.
|
|
230
|
+
* @param total the total value which equates to 100% complete, defaults to `100`.
|
|
231
|
+
* @param current the current value which is a portion of the total value, defaults to `0`.
|
|
232
|
+
*
|
|
233
|
+
* @return a handle to use when invoking {@link updateProgressBar}.
|
|
234
|
+
*/
|
|
235
|
+
showProgressBar(
|
|
236
|
+
units: string,
|
|
237
|
+
message?: string,
|
|
238
|
+
total?: number,
|
|
239
|
+
current?: number,
|
|
240
|
+
): Promise<number>;
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Hides a specified progress bar.
|
|
244
|
+
*
|
|
245
|
+
* NOTE: Showing the spinner will also hide ALL progress bars.
|
|
246
|
+
*
|
|
247
|
+
* @param handle the handle referring to the progress bar to be hidden.
|
|
248
|
+
*/
|
|
249
|
+
hideProgressBar(handle: number): Promise<void>;
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Hides all progress bars.
|
|
253
|
+
*
|
|
254
|
+
* NOTE: Showing the spinner will also hide ALL progress bars.
|
|
255
|
+
*/
|
|
256
|
+
hideAllProgressBars(): Promise<void>;
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Update a specific progress bar.
|
|
260
|
+
*
|
|
261
|
+
* @param handle the handle referring to the progress bar to be updated.
|
|
262
|
+
* @param current the current value to set on the progress bar.
|
|
263
|
+
* @param message an optional message to set on the progress bar, if not specified the initially specified message will be displayed.
|
|
264
|
+
*/
|
|
265
|
+
updateProgressBar(handle: number, current: number, message?: string): void;
|
|
266
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const SHUTDOWN_SERVICE_ID =
|
|
2
|
+
"@flowscripter/dynamic-cli-framework/shutdown-service";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Service allowing registration of callbacks for CLI shutdown.
|
|
6
|
+
*/
|
|
7
|
+
export default interface ShutdownService {
|
|
8
|
+
/**
|
|
9
|
+
* Register a callback method for CLI shutdown.
|
|
10
|
+
*/
|
|
11
|
+
addShutdownListener(callback: () => Promise<void>): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { LanguageFn as HighlightSyntax } from "highlight.js";
|
|
2
|
+
|
|
3
|
+
export const SYNTAX_HIGHLIGHTER_SERVICE_ID =
|
|
4
|
+
"@flowscripter/dynamic-cli-framework/highlighter-service";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Service providing syntax based color highlighting of text for the CLI using [highlight.js](https://highlightjs.org).
|
|
8
|
+
*/
|
|
9
|
+
export default interface SyntaxHighlighterService {
|
|
10
|
+
/**
|
|
11
|
+
* Register a new syntax.
|
|
12
|
+
*
|
|
13
|
+
* The recommended way to define a new language syntax is follow the instructions here:
|
|
14
|
+
*
|
|
15
|
+
* * https://highlightjs.readthedocs.io/en/latest/language-contribution.html
|
|
16
|
+
* * https://highlightjs.readthedocs.io/en/latest/building-testing.html
|
|
17
|
+
* * https://github.com/highlightjs/highlight.js/blob/main/docs/language-guide.rst
|
|
18
|
+
*
|
|
19
|
+
* There is a list of already defined languages available for import here:
|
|
20
|
+
*
|
|
21
|
+
* https://github.com/highlightjs/highlight.js/blob/main/SUPPORTED_LANGUAGES.md
|
|
22
|
+
*
|
|
23
|
+
* @param syntaxName the name used to refer to the syntax.
|
|
24
|
+
* @param syntaxDefinition the definition for the syntax conforming to the Highlight JS
|
|
25
|
+
* [language definition syntax]().
|
|
26
|
+
*/
|
|
27
|
+
registerSyntax(syntaxName: string, syntaxDefinition: HighlightSyntax): void;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Return the names of the currently registered syntaxes.
|
|
31
|
+
*/
|
|
32
|
+
getRegisteredSyntaxes(): ReadonlyArray<string>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Return a syntactically highlighted version of the provided text using the specified syntax.
|
|
36
|
+
* The returned text will include appropriate ASCII color codes.
|
|
37
|
+
*
|
|
38
|
+
* @param text the text to highlight.
|
|
39
|
+
* @param syntaxName the syntax to use.
|
|
40
|
+
*/
|
|
41
|
+
highlight(text: string, syntaxName: string): string;
|
|
42
|
+
}
|