@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,22 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import DefaultContext from "../../../src/runtime/DefaultContext.ts";
|
|
3
|
+
import { getCLIConfig } from "../../fixtures/CLIConfig.ts";
|
|
4
|
+
import AsciiBannerGeneratorServiceProvider from "../../../src/service/asciiBannerGenerator/AsciiBannerGeneratorServiceProvider.ts";
|
|
5
|
+
|
|
6
|
+
describe("AsciiBannerGeneratorServiceProvider Tests", () => {
|
|
7
|
+
test("AsciiBannerGeneratorServiceProvider provide and initService works", async () => {
|
|
8
|
+
const asciiBannerGeneratorServiceProvider =
|
|
9
|
+
new AsciiBannerGeneratorServiceProvider(
|
|
10
|
+
100,
|
|
11
|
+
);
|
|
12
|
+
const cliConfig = getCLIConfig();
|
|
13
|
+
const context = new DefaultContext(cliConfig);
|
|
14
|
+
|
|
15
|
+
const serviceInfo = await asciiBannerGeneratorServiceProvider.provide(
|
|
16
|
+
cliConfig,
|
|
17
|
+
);
|
|
18
|
+
expect(serviceInfo.commands.length).toEqual(0);
|
|
19
|
+
|
|
20
|
+
await asciiBannerGeneratorServiceProvider.initService(context);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import DefaultAsciiBannerGeneratorService from "../../../src/service/asciiBannerGenerator/DefaultAsciiBannerGeneratorService.ts";
|
|
3
|
+
|
|
4
|
+
// FIGlet font is converted to a JSON string and embedded in a simple JSON file: `{ "font": "<figlet font definition>" }`
|
|
5
|
+
import smallFont from "./small.flf.json" with { type: "json" };
|
|
6
|
+
describe("DefaultAsciiBannerGeneratorService Tests", () => {
|
|
7
|
+
test("standard font registered by default", () => {
|
|
8
|
+
const asciiBannerGeneratorService =
|
|
9
|
+
new DefaultAsciiBannerGeneratorService();
|
|
10
|
+
|
|
11
|
+
expect(asciiBannerGeneratorService.getRegisteredFonts()).toEqual([
|
|
12
|
+
"standard",
|
|
13
|
+
]);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test("Cannot register a font if already registered", () => {
|
|
17
|
+
const asciiBannerGeneratorService =
|
|
18
|
+
new DefaultAsciiBannerGeneratorService();
|
|
19
|
+
|
|
20
|
+
expect(() =>
|
|
21
|
+
asciiBannerGeneratorService.registerFont("standard", smallFont.font)
|
|
22
|
+
)
|
|
23
|
+
.toThrow();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test("Can register new font", () => {
|
|
27
|
+
const asciiBannerGeneratorService =
|
|
28
|
+
new DefaultAsciiBannerGeneratorService();
|
|
29
|
+
|
|
30
|
+
asciiBannerGeneratorService.registerFont("small", smallFont.font);
|
|
31
|
+
expect(asciiBannerGeneratorService.getRegisteredFonts()).toEqual([
|
|
32
|
+
"standard",
|
|
33
|
+
"small",
|
|
34
|
+
]);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test("Cannot generate with unknown font", async () => {
|
|
38
|
+
const asciiBannerGeneratorService =
|
|
39
|
+
new DefaultAsciiBannerGeneratorService();
|
|
40
|
+
|
|
41
|
+
await expect(asciiBannerGeneratorService.generate("foo", "small")).rejects
|
|
42
|
+
.toThrow();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test("Can generate with standard font", async () => {
|
|
46
|
+
const asciiBannerGeneratorService =
|
|
47
|
+
new DefaultAsciiBannerGeneratorService();
|
|
48
|
+
|
|
49
|
+
asciiBannerGeneratorService.registerFont("small", smallFont.font);
|
|
50
|
+
|
|
51
|
+
const generated = await asciiBannerGeneratorService.generate(
|
|
52
|
+
"foo",
|
|
53
|
+
"standard",
|
|
54
|
+
);
|
|
55
|
+
expect(generated).toMatchSnapshot();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test("Can generate with newly registered font", async () => {
|
|
59
|
+
const asciiBannerGeneratorService =
|
|
60
|
+
new DefaultAsciiBannerGeneratorService();
|
|
61
|
+
|
|
62
|
+
asciiBannerGeneratorService.registerFont("small", smallFont.font);
|
|
63
|
+
|
|
64
|
+
const generated = await asciiBannerGeneratorService.generate(
|
|
65
|
+
"foo",
|
|
66
|
+
"small",
|
|
67
|
+
);
|
|
68
|
+
expect(generated).toMatchSnapshot();
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Bun Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`DefaultAsciiBannerGeneratorService Tests Can generate with standard font 1`] = `
|
|
4
|
+
"
|
|
5
|
+
__
|
|
6
|
+
/ _| ___ ___
|
|
7
|
+
| |_ / _ \\ / _ \\
|
|
8
|
+
| _| (_) | (_) |
|
|
9
|
+
|_| \\___/ \\___/
|
|
10
|
+
|
|
11
|
+
"
|
|
12
|
+
`;
|
|
13
|
+
|
|
14
|
+
exports[`DefaultAsciiBannerGeneratorService Tests Can generate with newly registered font 1`] = `
|
|
15
|
+
"
|
|
16
|
+
__
|
|
17
|
+
/ _|___ ___
|
|
18
|
+
| _/ _ \\/ _ \\
|
|
19
|
+
|_| \\___/\\___/
|
|
20
|
+
|
|
21
|
+
"
|
|
22
|
+
`;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
{
|
|
2
|
+
"font": "flf2a$ 5 4 13 15 10 0 22415\nSmall by Glenn Chappell 4/93 -- based on Standard\nIncludes ISO Latin-1\nfiglet release 2.1 -- 12 Aug 1994\nPermission is hereby given to modify this font, as long as the\nmodifier's name is placed on a comment line.\n\nModified by Paul Burton <solution@earthlink.net> 12/96 to include new parameter\nsupported by FIGlet and FIGWin. May also be slightly modified for better use\nof new full-width/kern/smush alternatives, but default output is NOT changed.\n\n $@\n $@\n $@\n $@\n $@@\n _ @\n | |@\n |_|@\n (_)@\n @@\n _ _ @\n ( | )@\n V V @\n $ @\n @@\n _ _ @\n _| | |_ @\n |_ . _|@\n |_ _|@\n |_|_| @@\n @\n ||_@\n (_-<@\n / _/@\n || @@\n _ __ @\n (_)/ / @\n / /_ @\n /_/(_)@\n @@\n __ @\n / _|___ @\n > _|_ _|@\n \\_____| @\n @@\n _ @\n ( )@\n |/ @\n $ @\n @@\n __@\n / /@\n | | @\n | | @\n \\_\\@@\n __ @\n \\ \\ @\n | |@\n | |@\n /_/ @@\n @\n _/\\_@\n > <@\n \\/ @\n @@\n _ @\n _| |_ @\n |_ _|@\n |_| @\n @@\n @\n @\n _ @\n ( )@\n |/ @@\n @\n ___ @\n |___|@\n $ @\n @@\n @\n @\n _ @\n (_)@\n @@\n __@\n / /@\n / / @\n /_/ @\n @@\n __ @\n / \\ @\n | () |@\n \\__/ @\n @@\n _ @\n / |@\n | |@\n |_|@\n @@\n ___ @\n |_ )@\n / / @\n /___|@\n @@\n ____@\n |__ /@\n |_ \\@\n |___/@\n @@\n _ _ @\n | | | @\n |_ _|@\n |_| @\n @@\n ___ @\n | __|@\n |__ \\@\n |___/@\n @@\n __ @\n / / @\n / _ \\@\n \\___/@\n @@\n ____ @\n |__ |@\n / / @\n /_/ @\n @@\n ___ @\n ( _ )@\n / _ \\@\n \\___/@\n @@\n ___ @\n / _ \\@\n \\_, /@\n /_/ @\n @@\n _ @\n (_)@\n _ @\n (_)@\n @@\n _ @\n (_)@\n _ @\n ( )@\n |/ @@\n __@\n / /@\n < < @\n \\_\\@\n @@\n @\n ___ @\n |___|@\n |___|@\n @@\n __ @\n \\ \\ @\n > >@\n /_/ @\n @@\n ___ @\n |__ \\@\n /_/@\n (_) @\n @@\n ____ @\n / __ \\ @\n / / _` |@\n \\ \\__,_|@\n \\____/ @@\n _ @\n /_\\ @\n / _ \\ @\n /_/ \\_\\@\n @@\n ___ @\n | _ )@\n | _ \\@\n |___/@\n @@\n ___ @\n / __|@\n | (__ @\n \\___|@\n @@\n ___ @\n | \\ @\n | |) |@\n |___/ @\n @@\n ___ @\n | __|@\n | _| @\n |___|@\n @@\n ___ @\n | __|@\n | _| @\n |_| @\n @@\n ___ @\n / __|@\n | (_ |@\n \\___|@\n @@\n _ _ @\n | || |@\n | __ |@\n |_||_|@\n @@\n ___ @\n |_ _|@\n | | @\n |___|@\n @@\n _ @\n _ | |@\n | || |@\n \\__/ @\n @@\n _ __@\n | |/ /@\n | ' < @\n |_|\\_\\@\n @@\n _ @\n | | @\n | |__ @\n |____|@\n @@\n __ __ @\n | \\/ |@\n | |\\/| |@\n |_| |_|@\n @@\n _ _ @\n | \\| |@\n | .` |@\n |_|\\_|@\n @@\n ___ @\n / _ \\ @\n | (_) |@\n \\___/ @\n @@\n ___ @\n | _ \\@\n | _/@\n |_| @\n @@\n ___ @\n / _ \\ @\n | (_) |@\n \\__\\_\\@\n @@\n ___ @\n | _ \\@\n | /@\n |_|_\\@\n @@\n ___ @\n / __|@\n \\__ \\@\n |___/@\n @@\n _____ @\n |_ _|@\n | | @\n |_| @\n @@\n _ _ @\n | | | |@\n | |_| |@\n \\___/ @\n @@\n __ __@\n \\ \\ / /@\n \\ V / @\n \\_/ @\n @@\n __ __@\n \\ \\ / /@\n \\ \\/\\/ / @\n \\_/\\_/ @\n @@\n __ __@\n \\ \\/ /@\n > < @\n /_/\\_\\@\n @@\n __ __@\n \\ \\ / /@\n \\ V / @\n |_| @\n @@\n ____@\n |_ /@\n / / @\n /___|@\n @@\n __ @\n | _|@\n | | @\n | | @\n |__|@@\n __ @\n \\ \\ @\n \\ \\ @\n \\_\\@\n @@\n __ @\n |_ |@\n | |@\n | |@\n |__|@@\n /\\ @\n |/\\|@\n $ @\n $ @\n @@\n @\n @\n @\n ___ @\n |___|@@\n _ @\n ( )@\n \\|@\n $ @\n @@\n @\n __ _ @\n / _` |@\n \\__,_|@\n @@\n _ @\n | |__ @\n | '_ \\@\n |_.__/@\n @@\n @\n __ @\n / _|@\n \\__|@\n @@\n _ @\n __| |@\n / _` |@\n \\__,_|@\n @@\n @\n ___ @\n / -_)@\n \\___|@\n @@\n __ @\n / _|@\n | _|@\n |_| @\n @@\n @\n __ _ @\n / _` |@\n \\__, |@\n |___/ @@\n _ @\n | |_ @\n | ' \\ @\n |_||_|@\n @@\n _ @\n (_)@\n | |@\n |_|@\n @@\n _ @\n (_)@\n | |@\n _/ |@\n |__/ @@\n _ @\n | |__@\n | / /@\n |_\\_\\@\n @@\n _ @\n | |@\n | |@\n |_|@\n @@\n @\n _ __ @\n | ' \\ @\n |_|_|_|@\n @@\n @\n _ _ @\n | ' \\ @\n |_||_|@\n @@\n @\n ___ @\n / _ \\@\n \\___/@\n @@\n @\n _ __ @\n | '_ \\@\n | .__/@\n |_| @@\n @\n __ _ @\n / _` |@\n \\__, |@\n |_|@@\n @\n _ _ @\n | '_|@\n |_| @\n @@\n @\n ___@\n (_-<@\n /__/@\n @@\n _ @\n | |_ @\n | _|@\n \\__|@\n @@\n @\n _ _ @\n | || |@\n \\_,_|@\n @@\n @\n __ __@\n \\ V /@\n \\_/ @\n @@\n @\n __ __ __@\n \\ V V /@\n \\_/\\_/ @\n @@\n @\n __ __@\n \\ \\ /@\n /_\\_\\@\n @@\n @\n _ _ @\n | || |@\n \\_, |@\n |__/ @@\n @\n ___@\n |_ /@\n /__|@\n @@\n __@\n / /@\n _| | @\n | | @\n \\_\\@@\n _ @\n | |@\n | |@\n | |@\n |_|@@\n __ @\n \\ \\ @\n | |_@\n | | @\n /_/ @@\n /\\/|@\n |/\\/ @\n $ @\n $ @\n @@\n _ _ @\n (_)(_)@\n /--\\ @\n /_/\\_\\@\n @@\n _ _ @\n (_)(_)@\n / __ \\@\n \\____/@\n @@\n _ _ @\n (_) (_)@\n | |_| |@\n \\___/ @\n @@\n _ _ @\n (_)(_)@\n / _` |@\n \\__,_|@\n @@\n _ _ @\n (_)_(_)@\n / _ \\ @\n \\___/ @\n @@\n _ _ @\n (_)(_)@\n | || |@\n \\_,_|@\n @@\n ___ @\n / _ \\@\n | |< <@\n | ||_/@\n |_| @@\n160 NO-BREAK SPACE\n $@\n $@\n $@\n $@\n $@@\n161 INVERTED EXCLAMATION MARK\n _ @\n (_)@\n | |@\n |_|@\n @@\n162 CENT SIGN\n @\n || @\n / _)@\n \\ _)@\n || @@\n163 POUND SIGN\n __ @\n _/ _\\ @\n |_ _|_ @\n (_,___|@\n @@\n164 CURRENCY SIGN\n /\\_/\\@\n \\ . /@\n / _ \\@\n \\/ \\/@\n @@\n165 YEN SIGN\n __ __ @\n \\ V / @\n |__ __|@\n |__ __|@\n |_| @@\n166 BROKEN BAR\n _ @\n | |@\n |_|@\n | |@\n |_|@@\n167 SECTION SIGN\n __ @\n / _)@\n /\\ \\ @\n \\ \\/ @\n (__/ @@\n168 DIAERESIS\n _ _ @\n (_)(_)@\n $ $ @\n $ $ @\n @@\n169 COPYRIGHT SIGN\n ____ @\n / __ \\ @\n / / _| \\@\n \\ \\__| /@\n \\____/ @@\n170 FEMININE ORDINAL INDICATOR\n __ _ @\n / _` |@\n \\__,_|@\n |____|@\n @@\n171 LEFT-POINTING DOUBLE ANGLE QUOTATION MARK\n ____@\n / / /@\n < < < @\n \\_\\_\\@\n @@\n172 NOT SIGN\n ____ @\n |__ |@\n |_|@\n $ @\n @@\n173 SOFT HYPHEN\n @\n __ @\n |__|@\n $ @\n @@\n174 REGISTERED SIGN\n ____ @\n / __ \\ @\n / | -) \\@\n \\ ||\\\\ /@\n \\____/ @@\n175 MACRON\n ___ @\n |___|@\n $ @\n $ @\n @@\n176 DEGREE SIGN\n _ @\n /.\\@\n \\_/@\n $ @\n @@\n177 PLUS-MINUS SIGN\n _ @\n _| |_ @\n |_ _|@\n _|_|_ @\n |_____|@@\n178 SUPERSCRIPT TWO\n __ @\n |_ )@\n /__|@\n $ @\n @@\n179 SUPERSCRIPT THREE\n ___@\n |_ /@\n |__)@\n $ @\n @@\n180 ACUTE ACCENT\n __@\n /_/@\n $ @\n $ @\n @@\n181 MICRO SIGN\n @\n _ _ @\n | || |@\n | .,_|@\n |_| @@\n182 PILCROW SIGN\n ____ @\n / |@\n \\_ | |@\n |_|_|@\n @@\n183 MIDDLE DOT\n @\n _ @\n (_)@\n $ @\n @@\n184 CEDILLA\n @\n @\n @\n _ @\n )_)@@\n185 SUPERSCRIPT ONE\n _ @\n / |@\n |_|@\n $ @\n @@\n186 MASCULINE ORDINAL INDICATOR\n ___ @\n / _ \\@\n \\___/@\n |___|@\n @@\n187 RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK\n ____ @\n \\ \\ \\ @\n > > >@\n /_/_/ @\n @@\n188 VULGAR FRACTION ONE QUARTER\n _ __ @\n / |/ /__ @\n |_/ /_' |@\n /_/ |_|@\n @@\n189 VULGAR FRACTION ONE HALF\n _ __ @\n / |/ /_ @\n |_/ /_ )@\n /_//__|@\n @@\n190 VULGAR FRACTION THREE QUARTERS\n ___ __ @\n |_ // /__ @\n |__) /_' |@\n /_/ |_|@\n @@\n191 INVERTED QUESTION MARK\n _ @\n (_) @\n / /_ @\n \\___|@\n @@\n192 LATIN CAPITAL LETTER A WITH GRAVE\n __ @\n \\_\\ @\n /--\\ @\n /_/\\_\\@\n @@\n193 LATIN CAPITAL LETTER A WITH ACUTE\n __ @\n /_/ @\n /--\\ @\n /_/\\_\\@\n @@\n194 LATIN CAPITAL LETTER A WITH CIRCUMFLEX\n /\\ @\n |/\\| @\n /--\\ @\n /_/\\_\\@\n @@\n195 LATIN CAPITAL LETTER A WITH TILDE\n /\\/|@\n |/\\/ @\n /--\\ @\n /_/\\_\\@\n @@\n196 LATIN CAPITAL LETTER A WITH DIAERESIS\n _ _ @\n (_)(_)@\n /--\\ @\n /_/\\_\\@\n @@\n197 LATIN CAPITAL LETTER A WITH RING ABOVE\n __ @\n (()) @\n /--\\ @\n /_/\\_\\@\n @@\n198 LATIN CAPITAL LETTER AE\n ____ @\n /, __|@\n / _ _| @\n /_/|___|@\n @@\n199 LATIN CAPITAL LETTER C WITH CEDILLA\n ___ @\n / __|@\n | (__ @\n \\___|@\n )_) @@\n200 LATIN CAPITAL LETTER E WITH GRAVE\n __ @\n \\_\\@\n | -<@\n |__<@\n @@\n201 LATIN CAPITAL LETTER E WITH ACUTE\n __@\n /_/@\n | -<@\n |__<@\n @@\n202 LATIN CAPITAL LETTER E WITH CIRCUMFLEX\n /\\ @\n |/\\|@\n | -<@\n |__<@\n @@\n203 LATIN CAPITAL LETTER E WITH DIAERESIS\n _ _ @\n (_)(_)@\n | -< @\n |__< @\n @@\n204 LATIN CAPITAL LETTER I WITH GRAVE\n __ @\n \\_\\ @\n |_ _|@\n |___|@\n @@\n205 LATIN CAPITAL LETTER I WITH ACUTE\n __ @\n /_/ @\n |_ _|@\n |___|@\n @@\n206 LATIN CAPITAL LETTER I WITH CIRCUMFLEX\n //\\ @\n |/_\\|@\n |_ _|@\n |___|@\n @@\n207 LATIN CAPITAL LETTER I WITH DIAERESIS\n _ _ @\n (_)_(_)@\n |_ _| @\n |___| @\n @@\n208 LATIN CAPITAL LETTER ETH\n ____ @\n | __ \\ @\n |_ _|) |@\n |____/ @\n @@\n209 LATIN CAPITAL LETTER N WITH TILDE\n /\\/|@\n |/\\/ @\n | \\| |@\n |_|\\_|@\n @@\n210 LATIN CAPITAL LETTER O WITH GRAVE\n __ @\n \\_\\_ @\n / __ \\@\n \\____/@\n @@\n211 LATIN CAPITAL LETTER O WITH ACUTE\n __ @\n _/_/ @\n / __ \\@\n \\____/@\n @@\n212 LATIN CAPITAL LETTER O WITH CIRCUMFLEX\n /\\ @\n |/\\| @\n / __ \\@\n \\____/@\n @@\n213 LATIN CAPITAL LETTER O WITH TILDE\n /\\/|@\n |/\\/ @\n / __ \\@\n \\____/@\n @@\n214 LATIN CAPITAL LETTER O WITH DIAERESIS\n _ _ @\n (_)(_)@\n / __ \\@\n \\____/@\n @@\n215 MULTIPLICATION SIGN\n @\n /\\/\\@\n > <@\n \\/\\/@\n @@\n216 LATIN CAPITAL LETTER O WITH STROKE\n ____ @\n / _//\\ @\n | (//) |@\n \\//__/ @\n @@\n217 LATIN CAPITAL LETTER U WITH GRAVE\n __ @\n _\\_\\_ @\n | |_| |@\n \\___/ @\n @@\n218 LATIN CAPITAL LETTER U WITH ACUTE\n __ @\n _/_/_ @\n | |_| |@\n \\___/ @\n @@\n219 LATIN CAPITAL LETTER U WITH CIRCUMFLEX\n //\\ @\n |/ \\| @\n | |_| |@\n \\___/ @\n @@\n220 LATIN CAPITAL LETTER U WITH DIAERESIS\n _ _ @\n (_) (_)@\n | |_| |@\n \\___/ @\n @@\n221 LATIN CAPITAL LETTER Y WITH ACUTE\n __ @\n _/_/_@\n \\ V /@\n |_| @\n @@\n222 LATIN CAPITAL LETTER THORN\n _ @\n | |_ @\n | -_)@\n |_| @\n @@\n223 LATIN SMALL LETTER SHARP S\n ___ @\n / _ \\@\n | |< <@\n | ||_/@\n |_| @@\n224 LATIN SMALL LETTER A WITH GRAVE\n __ @\n \\_\\_ @\n / _` |@\n \\__,_|@\n @@\n225 LATIN SMALL LETTER A WITH ACUTE\n __ @\n _/_/ @\n / _` |@\n \\__,_|@\n @@\n226 LATIN SMALL LETTER A WITH CIRCUMFLEX\n /\\ @\n |/\\| @\n / _` |@\n \\__,_|@\n @@\n227 LATIN SMALL LETTER A WITH TILDE\n /\\/|@\n |/\\/ @\n / _` |@\n \\__,_|@\n @@\n228 LATIN SMALL LETTER A WITH DIAERESIS\n _ _ @\n (_)(_)@\n / _` |@\n \\__,_|@\n @@\n229 LATIN SMALL LETTER A WITH RING ABOVE\n __ @\n (()) @\n / _` |@\n \\__,_|@\n @@\n230 LATIN SMALL LETTER AE\n @\n __ ___ @\n / _` -_)@\n \\__,___|@\n @@\n231 LATIN SMALL LETTER C WITH CEDILLA\n @\n __ @\n / _|@\n \\__|@\n )_)@@\n232 LATIN SMALL LETTER E WITH GRAVE\n __ @\n \\_\\ @\n / -_)@\n \\___|@\n @@\n233 LATIN SMALL LETTER E WITH ACUTE\n __ @\n /_/ @\n / -_)@\n \\___|@\n @@\n234 LATIN SMALL LETTER E WITH CIRCUMFLEX\n //\\ @\n |/_\\|@\n / -_)@\n \\___|@\n @@\n235 LATIN SMALL LETTER E WITH DIAERESIS\n _ _ @\n (_)_(_)@\n / -_) @\n \\___| @\n @@\n236 LATIN SMALL LETTER I WITH GRAVE\n __ @\n \\_\\@\n | |@\n |_|@\n @@\n237 LATIN SMALL LETTER I WITH ACUTE\n __@\n /_/@\n | |@\n |_|@\n @@\n238 LATIN SMALL LETTER I WITH CIRCUMFLEX\n //\\ @\n |/_\\|@\n | | @\n |_| @\n @@\n239 LATIN SMALL LETTER I WITH DIAERESIS\n _ _ @\n (_)_(_)@\n | | @\n |_| @\n @@\n240 LATIN SMALL LETTER ETH\n \\\\/\\ @\n \\/\\\\ @\n / _` |@\n \\___/ @\n @@\n241 LATIN SMALL LETTER N WITH TILDE\n /\\/| @\n |/\\/ @\n | ' \\ @\n |_||_|@\n @@\n242 LATIN SMALL LETTER O WITH GRAVE\n __ @\n \\_\\ @\n / _ \\@\n \\___/@\n @@\n243 LATIN SMALL LETTER O WITH ACUTE\n __ @\n /_/ @\n / _ \\@\n \\___/@\n @@\n244 LATIN SMALL LETTER O WITH CIRCUMFLEX\n //\\ @\n |/_\\|@\n / _ \\@\n \\___/@\n @@\n245 LATIN SMALL LETTER O WITH TILDE\n /\\/|@\n |/\\/ @\n / _ \\@\n \\___/@\n @@\n246 LATIN SMALL LETTER O WITH DIAERESIS\n _ _ @\n (_)_(_)@\n / _ \\ @\n \\___/ @\n @@\n247 DIVISION SIGN\n _ @\n (_) @\n |___|@\n (_) @\n @@\n248 LATIN SMALL LETTER O WITH STROKE\n @\n ___ @\n / //\\@\n \\//_/@\n @@\n249 LATIN SMALL LETTER U WITH GRAVE\n __ @\n \\_\\_ @\n | || |@\n \\_,_|@\n @@\n250 LATIN SMALL LETTER U WITH ACUTE\n __ @\n _/_/ @\n | || |@\n \\_,_|@\n @@\n251 LATIN SMALL LETTER U WITH CIRCUMFLEX\n /\\ @\n |/\\| @\n | || |@\n \\_,_|@\n @@\n252 LATIN SMALL LETTER U WITH DIAERESIS\n _ _ @\n (_)(_)@\n | || |@\n \\_,_|@\n @@\n253 LATIN SMALL LETTER Y WITH ACUTE\n __ @\n _/_/ @\n | || |@\n \\_, |@\n |__/ @@\n254 LATIN SMALL LETTER THORN\n _ @\n | |__ @\n | '_ \\@\n | .__/@\n |_| @@\n255 LATIN SMALL LETTER Y WITH DIAERESIS\n _ _ @\n (_)(_)@\n | || |@\n \\_, |@\n |__/ @@\n"
|
|
3
|
+
}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { describe, expect, test } from "bun:test";
|
|
6
|
+
import ConfigurationServiceProvider from "../../../src/service/configuration/ConfigurationServiceProvider.ts";
|
|
7
|
+
import DefaultContext from "../../../src/runtime/DefaultContext.ts";
|
|
8
|
+
import { getCLIConfig } from "../../fixtures/CLIConfig.ts";
|
|
9
|
+
import { ArgumentValueTypeName } from "../../../src/api/argument/ArgumentValueTypes.ts";
|
|
10
|
+
import type KeyValueService from "../../../src/api/service/core/KeyValueService.ts";
|
|
11
|
+
import type SubCommand from "../../../src/api/command/SubCommand.ts";
|
|
12
|
+
|
|
13
|
+
function getConfig() {
|
|
14
|
+
return {
|
|
15
|
+
defaults: {
|
|
16
|
+
command1: {
|
|
17
|
+
arg1: [
|
|
18
|
+
1,
|
|
19
|
+
2,
|
|
20
|
+
],
|
|
21
|
+
arg2: {
|
|
22
|
+
"arg3": "foo",
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
command2: {
|
|
26
|
+
arg4: true,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
"key-values": {
|
|
30
|
+
commands: {
|
|
31
|
+
command1: {
|
|
32
|
+
foo1: "bar1",
|
|
33
|
+
foo2: "bar2",
|
|
34
|
+
},
|
|
35
|
+
command2: {
|
|
36
|
+
foo1: "bar3",
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
services: {
|
|
40
|
+
"service-id-1": {
|
|
41
|
+
foo1: "bar",
|
|
42
|
+
},
|
|
43
|
+
"service-id-2": {
|
|
44
|
+
foo2: "bar2",
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function getSubCommand(): SubCommand {
|
|
52
|
+
return {
|
|
53
|
+
name: "command2",
|
|
54
|
+
enableConfiguration: true,
|
|
55
|
+
options: [{
|
|
56
|
+
name: "arg4",
|
|
57
|
+
type: ArgumentValueTypeName.BOOLEAN,
|
|
58
|
+
}],
|
|
59
|
+
positionals: [],
|
|
60
|
+
execute: async (): Promise<void> => {},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
describe("ConfigurationServiceProvider Tests", () => {
|
|
64
|
+
test("ConfigurationServiceProvider provide works", async () => {
|
|
65
|
+
const configurationServiceProvider = new ConfigurationServiceProvider(
|
|
66
|
+
100,
|
|
67
|
+
false,
|
|
68
|
+
true,
|
|
69
|
+
);
|
|
70
|
+
const serviceInfo = await configurationServiceProvider.provide(
|
|
71
|
+
getCLIConfig(),
|
|
72
|
+
);
|
|
73
|
+
expect(serviceInfo.commands.length).toEqual(2);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("ConfigurationServiceProvider initService with no config works", async () => {
|
|
77
|
+
const configurationServiceProvider = new ConfigurationServiceProvider(
|
|
78
|
+
100,
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
const context = new DefaultContext(getCLIConfig());
|
|
82
|
+
|
|
83
|
+
await configurationServiceProvider.initService(context);
|
|
84
|
+
|
|
85
|
+
expect(configurationServiceProvider.getConfigString()).toEqual("{}");
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("ConfigurationServiceProvider initService with config works", async () => {
|
|
89
|
+
const configurationServiceProvider = new ConfigurationServiceProvider(
|
|
90
|
+
100,
|
|
91
|
+
false,
|
|
92
|
+
true,
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
const context = new DefaultContext(getCLIConfig());
|
|
96
|
+
|
|
97
|
+
const configFolder = await fs.mkdtemp(path.join(tmpdir(), "config-"));
|
|
98
|
+
const configLocation = path.join(configFolder, "config.json");
|
|
99
|
+
configurationServiceProvider.setConfigLocation(configLocation);
|
|
100
|
+
|
|
101
|
+
const config = getConfig();
|
|
102
|
+
|
|
103
|
+
await fs.writeFile(configLocation, JSON.stringify(config));
|
|
104
|
+
|
|
105
|
+
await configurationServiceProvider.initService(context);
|
|
106
|
+
|
|
107
|
+
expect(
|
|
108
|
+
configurationServiceProvider.getConfigString(),
|
|
109
|
+
).toEqual(
|
|
110
|
+
JSON.stringify(config, null, 2),
|
|
111
|
+
);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test("getDefaultArgumentValues works with config", async () => {
|
|
115
|
+
const configurationServiceProvider = new ConfigurationServiceProvider(
|
|
116
|
+
100,
|
|
117
|
+
false,
|
|
118
|
+
true,
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
const context = new DefaultContext(getCLIConfig());
|
|
122
|
+
|
|
123
|
+
const configFolder = await fs.mkdtemp(path.join(tmpdir(), "config-"));
|
|
124
|
+
const configLocation = path.join(configFolder, "config.json");
|
|
125
|
+
configurationServiceProvider.setConfigLocation(configLocation);
|
|
126
|
+
|
|
127
|
+
const config = getConfig();
|
|
128
|
+
|
|
129
|
+
await fs.writeFile(configLocation, JSON.stringify(config));
|
|
130
|
+
|
|
131
|
+
const subCommand = getSubCommand();
|
|
132
|
+
|
|
133
|
+
await configurationServiceProvider.initService(context);
|
|
134
|
+
|
|
135
|
+
expect(
|
|
136
|
+
configurationServiceProvider.getDefaultArgumentValues(
|
|
137
|
+
getCLIConfig(),
|
|
138
|
+
subCommand,
|
|
139
|
+
),
|
|
140
|
+
).toEqual(
|
|
141
|
+
config.defaults.command2,
|
|
142
|
+
);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test("getDefaultArgumentValues works with env vars", async () => {
|
|
146
|
+
try {
|
|
147
|
+
const configurationServiceProvider = new ConfigurationServiceProvider(
|
|
148
|
+
100,
|
|
149
|
+
true,
|
|
150
|
+
true,
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
const context = new DefaultContext(getCLIConfig());
|
|
154
|
+
|
|
155
|
+
process.env["FOO_COMMAND2_ARG4"] = "true";
|
|
156
|
+
|
|
157
|
+
const subCommand = getSubCommand();
|
|
158
|
+
|
|
159
|
+
await configurationServiceProvider.initService(context);
|
|
160
|
+
|
|
161
|
+
expect(
|
|
162
|
+
configurationServiceProvider.getDefaultArgumentValues(
|
|
163
|
+
getCLIConfig(),
|
|
164
|
+
subCommand,
|
|
165
|
+
),
|
|
166
|
+
).toEqual(
|
|
167
|
+
{ arg4: "true" },
|
|
168
|
+
);
|
|
169
|
+
} finally {
|
|
170
|
+
delete process.env["FOO_COMMAND2_ARG4"];
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
test("setCommandKeyValueScope works", async () => {
|
|
175
|
+
const configurationServiceProvider = new ConfigurationServiceProvider(
|
|
176
|
+
100,
|
|
177
|
+
false,
|
|
178
|
+
true,
|
|
179
|
+
true,
|
|
180
|
+
);
|
|
181
|
+
const cliConfig = getCLIConfig();
|
|
182
|
+
const context = new DefaultContext(cliConfig);
|
|
183
|
+
|
|
184
|
+
const configFolder = await fs.mkdtemp(path.join(tmpdir(), "config-"));
|
|
185
|
+
const configLocation = path.join(configFolder, "config.json");
|
|
186
|
+
configurationServiceProvider.setConfigLocation(configLocation);
|
|
187
|
+
|
|
188
|
+
const config = getConfig();
|
|
189
|
+
|
|
190
|
+
await fs.writeFile(configLocation, JSON.stringify(config));
|
|
191
|
+
|
|
192
|
+
const serviceInfo = await configurationServiceProvider.provide(cliConfig);
|
|
193
|
+
|
|
194
|
+
await configurationServiceProvider.initService(context);
|
|
195
|
+
|
|
196
|
+
const keyValueService = serviceInfo.service! as KeyValueService;
|
|
197
|
+
|
|
198
|
+
configurationServiceProvider.setCommandKeyValueScope("command2");
|
|
199
|
+
|
|
200
|
+
expect(keyValueService.hasKey("foo2")).toBeFalse();
|
|
201
|
+
|
|
202
|
+
await configurationServiceProvider.clearKeyValueScope();
|
|
203
|
+
configurationServiceProvider.setCommandKeyValueScope("command1");
|
|
204
|
+
|
|
205
|
+
expect(keyValueService.getKey("foo2")).toEqual("bar2");
|
|
206
|
+
|
|
207
|
+
await configurationServiceProvider.clearKeyValueScope();
|
|
208
|
+
|
|
209
|
+
expect(() => keyValueService.hasKey("foo2")).toThrow();
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
test("setServiceKeyValueScope works", async () => {
|
|
213
|
+
const configurationServiceProvider = new ConfigurationServiceProvider(
|
|
214
|
+
100,
|
|
215
|
+
false,
|
|
216
|
+
true,
|
|
217
|
+
true,
|
|
218
|
+
);
|
|
219
|
+
const cliConfig = getCLIConfig();
|
|
220
|
+
const context = new DefaultContext(cliConfig);
|
|
221
|
+
|
|
222
|
+
const configFolder = await fs.mkdtemp(path.join(tmpdir(), "config-"));
|
|
223
|
+
const configLocation = path.join(configFolder, "config.json");
|
|
224
|
+
configurationServiceProvider.setConfigLocation(configLocation);
|
|
225
|
+
|
|
226
|
+
const config = getConfig();
|
|
227
|
+
|
|
228
|
+
await fs.writeFile(configLocation, JSON.stringify(config));
|
|
229
|
+
|
|
230
|
+
const serviceInfo = await configurationServiceProvider.provide(cliConfig);
|
|
231
|
+
|
|
232
|
+
await configurationServiceProvider.initService(context);
|
|
233
|
+
|
|
234
|
+
const keyValueService = serviceInfo.service! as KeyValueService;
|
|
235
|
+
|
|
236
|
+
configurationServiceProvider.setServiceKeyValueScope("service-id-2");
|
|
237
|
+
|
|
238
|
+
expect(keyValueService.hasKey("foo1")).toBeFalse();
|
|
239
|
+
|
|
240
|
+
await configurationServiceProvider.clearKeyValueScope();
|
|
241
|
+
configurationServiceProvider.setServiceKeyValueScope("service-id-1");
|
|
242
|
+
|
|
243
|
+
expect(keyValueService.getKey("foo1")).toEqual("bar");
|
|
244
|
+
|
|
245
|
+
await configurationServiceProvider.clearKeyValueScope();
|
|
246
|
+
|
|
247
|
+
expect(() => keyValueService.hasKey("foo1")).toThrow();
|
|
248
|
+
});
|
|
249
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import DefaultKeyValueService from "../../../src/service/configuration/DefaultKeyValueService.ts";
|
|
3
|
+
|
|
4
|
+
describe("DefaultKeyValueService Tests", () => {
|
|
5
|
+
test("Setting data works", () => {
|
|
6
|
+
const keyValueService = new DefaultKeyValueService();
|
|
7
|
+
|
|
8
|
+
keyValueService.setKeyValueData(new Map([["foo", "bar"]]));
|
|
9
|
+
|
|
10
|
+
expect(keyValueService.hasKey("foo")).toBeTrue();
|
|
11
|
+
expect(keyValueService.getKey("foo")).toEqual("bar");
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test("Cannot set data without clearing", () => {
|
|
15
|
+
const keyValueService = new DefaultKeyValueService();
|
|
16
|
+
|
|
17
|
+
keyValueService.setKeyValueData(new Map());
|
|
18
|
+
expect(() => keyValueService.setKeyValueData(new Map())).toThrow();
|
|
19
|
+
|
|
20
|
+
keyValueService.clearKeyValueData();
|
|
21
|
+
keyValueService.setKeyValueData(new Map());
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("Cannot modify data before setting it", () => {
|
|
25
|
+
const keyValueService = new DefaultKeyValueService();
|
|
26
|
+
|
|
27
|
+
expect(() => keyValueService.setKey("foo", "bar")).toThrow();
|
|
28
|
+
expect(() => keyValueService.hasKey("foo")).toThrow();
|
|
29
|
+
expect(() => keyValueService.getKey("foo")).toThrow();
|
|
30
|
+
expect(() => keyValueService.deleteKey("foo")).toThrow();
|
|
31
|
+
|
|
32
|
+
keyValueService.setKeyValueData(new Map());
|
|
33
|
+
|
|
34
|
+
keyValueService.setKey("foo", "bar");
|
|
35
|
+
expect(keyValueService.hasKey("foo")).toBeTrue();
|
|
36
|
+
expect(keyValueService.getKey("foo")).toEqual("bar");
|
|
37
|
+
keyValueService.deleteKey("foo");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("Dirty state is managed correctly", () => {
|
|
41
|
+
const keyValueService = new DefaultKeyValueService();
|
|
42
|
+
|
|
43
|
+
expect(keyValueService.isDirty()).toBeFalse();
|
|
44
|
+
|
|
45
|
+
keyValueService.setKeyValueData(new Map());
|
|
46
|
+
|
|
47
|
+
expect(keyValueService.isDirty()).toBeFalse();
|
|
48
|
+
|
|
49
|
+
keyValueService.setKey("foo", "bar");
|
|
50
|
+
|
|
51
|
+
expect(keyValueService.isDirty()).toBeTrue();
|
|
52
|
+
|
|
53
|
+
keyValueService.clearKeyValueData();
|
|
54
|
+
|
|
55
|
+
expect(keyValueService.isDirty()).toBeFalse();
|
|
56
|
+
|
|
57
|
+
keyValueService.setKeyValueData(new Map([["foo", "bar"]]));
|
|
58
|
+
|
|
59
|
+
expect(keyValueService.isDirty()).toBeFalse();
|
|
60
|
+
|
|
61
|
+
keyValueService.deleteKey("foo");
|
|
62
|
+
|
|
63
|
+
expect(keyValueService.isDirty()).toBeTrue();
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { getCLIConfig } from "../../fixtures/CLIConfig.ts";
|
|
3
|
+
import BannerServiceProvider from "../../../src/service/banner/BannerServiceProvider.ts";
|
|
4
|
+
import DefaultPrinterService from "../../../src/service/printer/DefaultPrinterService.ts";
|
|
5
|
+
import { PRINTER_SERVICE_ID } from "../../../src/api/service/core/PrinterService.ts";
|
|
6
|
+
import DefaultContext from "../../../src/runtime/DefaultContext.ts";
|
|
7
|
+
import { ASCII_BANNER_GENERATOR_SERVICE_ID } from "../../../src/api/service/core/AsciiBannerGeneratorService.ts";
|
|
8
|
+
import DefaultAsciiBannerGeneratorService from "../../../src/service/asciiBannerGenerator/DefaultAsciiBannerGeneratorService.ts";
|
|
9
|
+
import TtyTerminal from "../../../src/service/printer/terminal/TtyTerminal.ts";
|
|
10
|
+
import StreamString from "../../fixtures/StreamString.ts";
|
|
11
|
+
import TtyStyler from "../../../src/service/printer/terminal/TtyStyler.ts";
|
|
12
|
+
|
|
13
|
+
describe("BannerServiceProvider Tests", () => {
|
|
14
|
+
test("BannerServiceProvider provide works", async () => {
|
|
15
|
+
const bannerServiceProvider = new BannerServiceProvider(100);
|
|
16
|
+
const serviceInfo = await bannerServiceProvider.provide(getCLIConfig());
|
|
17
|
+
expect(serviceInfo.commands.length).toEqual(1);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test("BannerServiceProvider initService works", async () => {
|
|
21
|
+
const dummyStdout = new StreamString();
|
|
22
|
+
const dummyStderr = new StreamString();
|
|
23
|
+
const printer = new DefaultPrinterService(
|
|
24
|
+
dummyStdout.writableStream,
|
|
25
|
+
dummyStderr.writableStream,
|
|
26
|
+
true,
|
|
27
|
+
true,
|
|
28
|
+
new TtyTerminal(dummyStderr.writeStream),
|
|
29
|
+
new TtyStyler(3),
|
|
30
|
+
);
|
|
31
|
+
printer.colorEnabled = false;
|
|
32
|
+
|
|
33
|
+
const asciiBannerGenerator = new DefaultAsciiBannerGeneratorService();
|
|
34
|
+
const context = new DefaultContext(getCLIConfig());
|
|
35
|
+
|
|
36
|
+
context.addServiceInstance(PRINTER_SERVICE_ID, printer);
|
|
37
|
+
context.addServiceInstance(
|
|
38
|
+
ASCII_BANNER_GENERATOR_SERVICE_ID,
|
|
39
|
+
asciiBannerGenerator,
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const bannerServiceProvider = new BannerServiceProvider(100);
|
|
43
|
+
await bannerServiceProvider.initService(context);
|
|
44
|
+
|
|
45
|
+
expect(bannerServiceProvider.printBanner).toBeTrue();
|
|
46
|
+
|
|
47
|
+
expect(dummyStdout.getString()).toMatchSnapshot();
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import NoBannerCommand from "../../../../src/service/banner/command/NoBannerCommand.ts";
|
|
3
|
+
import DefaultContext from "../../../../src/runtime/DefaultContext.ts";
|
|
4
|
+
import { getCLIConfig } from "../../../fixtures/CLIConfig.ts";
|
|
5
|
+
import BannerServiceProvider from "../../../../src/service/banner/BannerServiceProvider.ts";
|
|
6
|
+
|
|
7
|
+
describe("NoBannerCommand Tests", () => {
|
|
8
|
+
test("No banner works", async () => {
|
|
9
|
+
const bannerServiceProvider = new BannerServiceProvider(100);
|
|
10
|
+
const noBannerCommand = new NoBannerCommand(bannerServiceProvider, 110);
|
|
11
|
+
|
|
12
|
+
expect(bannerServiceProvider.printBanner).toBeTrue();
|
|
13
|
+
|
|
14
|
+
await noBannerCommand.execute(
|
|
15
|
+
new DefaultContext(getCLIConfig()),
|
|
16
|
+
true,
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
expect(bannerServiceProvider.printBanner).toBeFalse();
|
|
20
|
+
});
|
|
21
|
+
});
|