@flowscripter/example-cli 1.6.0 → 1.8.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/bun.lock +6 -5
- package/functional_tests/features/environment.py +9 -0
- package/functional_tests/features/support/pexpect_wrapper.py +2 -1
- package/functional_tests/features/support/subprocess_wrapper.py +37 -8
- package/functional_tests/features/upgrade.feature +6 -0
- package/package.json +4 -3
- package/src/cli.ts +40 -18
- package/src/commands/arg-parsing.ts +10 -10
- package/src/commands/banners.ts +2 -2
- package/src/commands/completion.ts +2 -2
- package/src/commands/configuration.ts +13 -12
- package/src/commands/image.ts +2 -2
- package/src/commands/interruption.ts +2 -2
- package/src/commands/printing.ts +2 -2
- package/src/commands/prompting.ts +5 -5
package/bun.lock
CHANGED
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
"": {
|
|
6
6
|
"name": "@flowscripter/example-cli",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@flowscripter/dynamic-cli-framework": "
|
|
9
|
-
"@flowscripter/dynamic-
|
|
8
|
+
"@flowscripter/dynamic-cli-framework": "4.0.0",
|
|
9
|
+
"@flowscripter/dynamic-cli-framework-api": "^1.5.0",
|
|
10
|
+
"@flowscripter/dynamic-plugin-framework": "2.0.0",
|
|
10
11
|
},
|
|
11
12
|
"devDependencies": {
|
|
12
13
|
"@types/bun": "^1.3.14",
|
|
@@ -20,11 +21,11 @@
|
|
|
20
21
|
},
|
|
21
22
|
},
|
|
22
23
|
"packages": {
|
|
23
|
-
"@flowscripter/dynamic-cli-framework": ["@flowscripter/dynamic-cli-framework@
|
|
24
|
+
"@flowscripter/dynamic-cli-framework": ["@flowscripter/dynamic-cli-framework@4.0.0", "", { "dependencies": { "@flowscripter/dynamic-cli-framework-api": "^1.5.0", "@flowscripter/dynamic-plugin-framework": "2.0.0", "emphasize": "^7.0.0", "fastest-levenshtein": "^1.0.16", "figlet": "^1.11.0", "highlight.js": "^11.11.1", "prettier": "^3.9.4", "semver": "^7.7.3", "supports-color": "^10.2.2", "supports-terminal-graphics": "^0.1.0" }, "peerDependencies": { "typescript": "^6.0.3" } }, "sha512-khzIXzaLWNHzbNrNMH7TrDFyAwclPnu4CrsRgL+IYU3nfnsN39K5pwd1MAKTFYBQddqxVa/ZMOFbPRMwz1el4w=="],
|
|
24
25
|
|
|
25
|
-
"@flowscripter/dynamic-cli-framework-api": ["@flowscripter/dynamic-cli-framework-api@1.
|
|
26
|
+
"@flowscripter/dynamic-cli-framework-api": ["@flowscripter/dynamic-cli-framework-api@1.5.0", "", { "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-Tjs5rtaL7kEVZAdO2bM1vdbzCp5R5qGJxRFif6T1uilV5qQaVF92t1R90ndjSSb9G9KnyTDdhHe+NbpDOllvtA=="],
|
|
26
27
|
|
|
27
|
-
"@flowscripter/dynamic-plugin-framework": ["@flowscripter/dynamic-plugin-framework@
|
|
28
|
+
"@flowscripter/dynamic-plugin-framework": ["@flowscripter/dynamic-plugin-framework@2.0.0", "", { "dependencies": { "semver": "^7.8.5" }, "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-LPq4JXqsWttvNgE7Z5fim3h78xfeF/754gL7yI4PMjxfIvAZeyJhqsUElXOMEzNIrY9bXTqVWQJBpKO0+Vl61A=="],
|
|
28
29
|
|
|
29
30
|
"@oxfmt/binding-android-arm-eabi": ["@oxfmt/binding-android-arm-eabi@0.56.0", "", { "os": "android", "cpu": "arm" }, "sha512-CSCxi7ovYojgfdPOdUb9T508HKeAdDIKeRGg7x8IZwVJrWz9gVgX7MbUnFqtQAE4QvoNo07mj2JlwnOzJw4qqA=="],
|
|
30
31
|
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import platform
|
|
3
|
+
import sys
|
|
3
4
|
|
|
4
5
|
from support.pexpect_wrapper import PExpectWrapper
|
|
5
6
|
|
|
6
7
|
IS_WINDOWS = platform.system() == 'Windows'
|
|
7
8
|
|
|
9
|
+
if IS_WINDOWS:
|
|
10
|
+
# Windows' legacy console codepage (e.g. cp1252) cannot encode several Unicode icons used
|
|
11
|
+
# in example-cli's coloured output (e.g. the U+203C alert icon), crashing behave's pretty
|
|
12
|
+
# formatter with UnicodeEncodeError whenever a failure message contains one. Reconfigure
|
|
13
|
+
# the streams to UTF-8, which covers them, before any output is written.
|
|
14
|
+
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
|
|
15
|
+
sys.stderr.reconfigure(encoding='utf-8', errors='replace')
|
|
16
|
+
|
|
8
17
|
|
|
9
18
|
def before_scenario(context, scenario):
|
|
10
19
|
|
|
@@ -31,6 +31,7 @@ class PExpectWrapper:
|
|
|
31
31
|
def expect(self, message):
|
|
32
32
|
assert self.child is not None
|
|
33
33
|
|
|
34
|
+
remaining = list(self.output)
|
|
34
35
|
found = ''
|
|
35
36
|
while len(self.output) > 0:
|
|
36
37
|
next_line = self.output.pop(0)
|
|
@@ -39,7 +40,7 @@ class PExpectWrapper:
|
|
|
39
40
|
found = next_line
|
|
40
41
|
break
|
|
41
42
|
|
|
42
|
-
assert found != '', 'expected {} in output'.format(message)
|
|
43
|
+
assert found != '', 'expected "{}" in output, got: {!r}'.format(message, remaining)
|
|
43
44
|
|
|
44
45
|
def expect_eof(self):
|
|
45
46
|
assert self.child is not None
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import platform
|
|
1
2
|
import shlex
|
|
2
3
|
import subprocess
|
|
3
4
|
import logging
|
|
@@ -5,6 +6,24 @@ import logging
|
|
|
5
6
|
log = logging.getLogger("subprocess_wrapper")
|
|
6
7
|
|
|
7
8
|
|
|
9
|
+
def _dump_process_tree():
|
|
10
|
+
# TEMPORARY: diagnosing an intermittent Windows-only hang in `plugin:add`. Dumps the OS
|
|
11
|
+
# process list on timeout so we can see whether a child npm/node process is stuck vs. our
|
|
12
|
+
# own process. Remove once root-caused.
|
|
13
|
+
try:
|
|
14
|
+
if platform.system() == 'Windows':
|
|
15
|
+
out = subprocess.run(
|
|
16
|
+
['tasklist', '/v'], capture_output=True, text=True, timeout=10
|
|
17
|
+
).stdout
|
|
18
|
+
else:
|
|
19
|
+
out = subprocess.run(
|
|
20
|
+
['ps', '-ef'], capture_output=True, text=True, timeout=10
|
|
21
|
+
).stdout
|
|
22
|
+
print('DEBUG: process list at timeout:\n{}'.format(out), flush=True)
|
|
23
|
+
except Exception as e:
|
|
24
|
+
print('DEBUG: failed to dump process list: {}'.format(e), flush=True)
|
|
25
|
+
|
|
26
|
+
|
|
8
27
|
class SubprocessWrapper:
|
|
9
28
|
|
|
10
29
|
def __init__(self, executable):
|
|
@@ -15,14 +34,24 @@ class SubprocessWrapper:
|
|
|
15
34
|
|
|
16
35
|
def run(self, args='', stdin_text=None, timeout=30):
|
|
17
36
|
cmd = [self.executable] + (shlex.split(args) if args else [])
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
37
|
+
# TEMPORARY: plain print() (not logging.debug) so this shows up in CI output regardless
|
|
38
|
+
# of behave's default log-capture level, while diagnosing an intermittent Windows-only
|
|
39
|
+
# hang in `plugin:add`. Remove once root-caused.
|
|
40
|
+
print('DEBUG: running: {}'.format(cmd), flush=True)
|
|
41
|
+
try:
|
|
42
|
+
result = subprocess.run(
|
|
43
|
+
cmd, capture_output=True, text=True, timeout=timeout, input=stdin_text,
|
|
44
|
+
encoding='utf-8', errors='replace'
|
|
45
|
+
)
|
|
46
|
+
except subprocess.TimeoutExpired as e:
|
|
47
|
+
print('DEBUG: TIMED OUT after {}s'.format(timeout), flush=True)
|
|
48
|
+
print('DEBUG: partial stdout: {!r}'.format(e.stdout), flush=True)
|
|
49
|
+
print('DEBUG: partial stderr: {!r}'.format(e.stderr), flush=True)
|
|
50
|
+
_dump_process_tree()
|
|
51
|
+
raise
|
|
23
52
|
self.stdout = result.stdout
|
|
24
53
|
self.stderr = result.stderr
|
|
25
54
|
self.returncode = result.returncode
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
55
|
+
print('DEBUG: stdout: {!r}'.format(self.stdout), flush=True)
|
|
56
|
+
print('DEBUG: stderr: {!r}'.format(self.stderr), flush=True)
|
|
57
|
+
print('DEBUG: returncode: {}'.format(self.returncode), flush=True)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flowscripter/example-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "Simple example CLI using https://github.com/flowscripter/dynamic-cli-framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bun",
|
|
@@ -24,8 +24,9 @@
|
|
|
24
24
|
"access": "public"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@flowscripter/dynamic-cli-framework": "
|
|
28
|
-
"@flowscripter/dynamic-
|
|
27
|
+
"@flowscripter/dynamic-cli-framework": "4.0.0",
|
|
28
|
+
"@flowscripter/dynamic-cli-framework-api": "^1.5.0",
|
|
29
|
+
"@flowscripter/dynamic-plugin-framework": "2.0.0"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"@types/bun": "^1.3.14",
|
package/src/cli.ts
CHANGED
|
@@ -2,15 +2,11 @@ import {
|
|
|
2
2
|
AsciiBannerGeneratorServiceProvider,
|
|
3
3
|
BannerServiceProvider,
|
|
4
4
|
DataDumpGeneratorServiceProvider,
|
|
5
|
-
|
|
5
|
+
launchMultiCommandCLI,
|
|
6
6
|
SyntaxHighlighterServiceProvider,
|
|
7
7
|
TreePrinterServiceProvider,
|
|
8
8
|
} from "@flowscripter/dynamic-cli-framework";
|
|
9
|
-
import {
|
|
10
|
-
NpmPluginManager,
|
|
11
|
-
NpmPluginRepository,
|
|
12
|
-
NpmjsPluginRepository,
|
|
13
|
-
} from "@flowscripter/dynamic-plugin-framework";
|
|
9
|
+
import { SupportedArch, SupportedOs } from "@flowscripter/dynamic-cli-framework-api";
|
|
14
10
|
import demo from "./commands/demo.ts";
|
|
15
11
|
import packageJson from "../package.json";
|
|
16
12
|
import path from "node:path";
|
|
@@ -18,19 +14,8 @@ import os from "node:os";
|
|
|
18
14
|
|
|
19
15
|
export async function cli(): Promise<void> {
|
|
20
16
|
const pluginsDir = path.join(os.homedir(), ".example-cli", "plugins", "node_modules");
|
|
21
|
-
const pluginManager = new NpmPluginManager(
|
|
22
|
-
[
|
|
23
|
-
new NpmjsPluginRepository({
|
|
24
|
-
name: "npmjs",
|
|
25
|
-
registryUrl: "https://registry.npmjs.org",
|
|
26
|
-
packageJsonNamespace: "dynamic-cli-framework",
|
|
27
|
-
}),
|
|
28
|
-
],
|
|
29
|
-
new NpmPluginRepository(pluginsDir, "dynamic-cli-framework"),
|
|
30
|
-
);
|
|
31
17
|
|
|
32
|
-
await
|
|
33
|
-
pluginManager,
|
|
18
|
+
await launchMultiCommandCLI(
|
|
34
19
|
[demo],
|
|
35
20
|
"Simple example CLI using dynamic-cli-framework.",
|
|
36
21
|
"example-cli",
|
|
@@ -50,6 +35,43 @@ export async function cli(): Promise<void> {
|
|
|
50
35
|
completionServiceEnabled: true,
|
|
51
36
|
imagePrinterServiceEnabled: true,
|
|
52
37
|
spawnServiceEnabled: true,
|
|
38
|
+
fetchServiceEnabled: true,
|
|
39
|
+
upgradeServiceEnabled: true,
|
|
40
|
+
pluginServiceEnabled: true,
|
|
41
|
+
pluginServiceRemoteConfig: {
|
|
42
|
+
name: "npmjs",
|
|
43
|
+
registryUrl: "https://registry.npmjs.org",
|
|
44
|
+
packageJsonNamespace: "dynamic-cli-framework",
|
|
45
|
+
},
|
|
46
|
+
pluginServiceLocalConfig: {
|
|
47
|
+
nodeModulesPath: pluginsDir,
|
|
48
|
+
packageJsonNamespace: "dynamic-cli-framework",
|
|
49
|
+
},
|
|
50
|
+
upgradeLocationsConfig: {
|
|
51
|
+
supportedPlatforms: [
|
|
52
|
+
{ os: SupportedOs.LINUX, arch: SupportedArch.X64 },
|
|
53
|
+
{ os: SupportedOs.LINUX, arch: SupportedArch.ARM64 },
|
|
54
|
+
{ os: SupportedOs.MACOS, arch: SupportedArch.X64 },
|
|
55
|
+
{ os: SupportedOs.MACOS, arch: SupportedArch.ARM64 },
|
|
56
|
+
{ os: SupportedOs.WINDOWS, arch: SupportedArch.X64 },
|
|
57
|
+
],
|
|
58
|
+
githubRelease: {
|
|
59
|
+
owner: "flowscripter",
|
|
60
|
+
repo: "example-cli",
|
|
61
|
+
assetPattern: "example-cli_{os}_{arch}.zip",
|
|
62
|
+
},
|
|
63
|
+
linuxScript: {
|
|
64
|
+
scriptUrl:
|
|
65
|
+
"https://raw.githubusercontent.com/flowscripter/example-cli/main/script/install.sh",
|
|
66
|
+
},
|
|
67
|
+
homebrew: {
|
|
68
|
+
tap: "flowscripter/tap",
|
|
69
|
+
formula: "example-cli",
|
|
70
|
+
},
|
|
71
|
+
winget: {
|
|
72
|
+
packageId: "Flowscripter.example-cli",
|
|
73
|
+
},
|
|
74
|
+
},
|
|
53
75
|
},
|
|
54
76
|
);
|
|
55
77
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
-
type
|
|
3
|
-
|
|
2
|
+
type Values,
|
|
3
|
+
ValueTypeName,
|
|
4
4
|
ComplexValueTypeName,
|
|
5
5
|
type Context,
|
|
6
6
|
PRINTER_SERVICE_ID,
|
|
@@ -17,21 +17,21 @@ const argParsing: SubCommand = {
|
|
|
17
17
|
{
|
|
18
18
|
name: "booleanOption",
|
|
19
19
|
description: "A boolean option",
|
|
20
|
-
type:
|
|
20
|
+
type: ValueTypeName.BOOLEAN,
|
|
21
21
|
shortAlias: "b",
|
|
22
22
|
isOptional: true,
|
|
23
23
|
},
|
|
24
24
|
{
|
|
25
25
|
name: "numberOption",
|
|
26
26
|
description: "A number option",
|
|
27
|
-
type:
|
|
27
|
+
type: ValueTypeName.NUMBER,
|
|
28
28
|
shortAlias: "n",
|
|
29
29
|
isOptional: true,
|
|
30
30
|
},
|
|
31
31
|
{
|
|
32
32
|
name: "stringOption",
|
|
33
33
|
description: "A string option",
|
|
34
|
-
type:
|
|
34
|
+
type: ValueTypeName.STRING,
|
|
35
35
|
shortAlias: "s",
|
|
36
36
|
isOptional: true,
|
|
37
37
|
},
|
|
@@ -45,7 +45,7 @@ const argParsing: SubCommand = {
|
|
|
45
45
|
{
|
|
46
46
|
name: "numberSubOption",
|
|
47
47
|
description: "A number sub-option",
|
|
48
|
-
type:
|
|
48
|
+
type: ValueTypeName.NUMBER,
|
|
49
49
|
shortAlias: "n",
|
|
50
50
|
isArray: true,
|
|
51
51
|
},
|
|
@@ -56,17 +56,17 @@ const argParsing: SubCommand = {
|
|
|
56
56
|
{
|
|
57
57
|
name: "booleanPositional",
|
|
58
58
|
description: "A boolean positional",
|
|
59
|
-
type:
|
|
59
|
+
type: ValueTypeName.BOOLEAN,
|
|
60
60
|
},
|
|
61
61
|
{
|
|
62
62
|
name: "numberPositional",
|
|
63
63
|
description: "A number positional",
|
|
64
|
-
type:
|
|
64
|
+
type: ValueTypeName.NUMBER,
|
|
65
65
|
},
|
|
66
66
|
{
|
|
67
67
|
name: "stringPositional",
|
|
68
68
|
description: "A string positional",
|
|
69
|
-
type:
|
|
69
|
+
type: ValueTypeName.STRING,
|
|
70
70
|
},
|
|
71
71
|
],
|
|
72
72
|
usageExamples: [
|
|
@@ -114,7 +114,7 @@ const argParsing: SubCommand = {
|
|
|
114
114
|
],
|
|
115
115
|
},
|
|
116
116
|
],
|
|
117
|
-
async execute(context: Context, argumentValues:
|
|
117
|
+
async execute(context: Context, argumentValues: Values): Promise<void> {
|
|
118
118
|
const printerService = context.getServiceById(PRINTER_SERVICE_ID) as PrinterService;
|
|
119
119
|
const highlighterService = context.getServiceById(
|
|
120
120
|
SYNTAX_HIGHLIGHTER_SERVICE_ID,
|
package/src/commands/banners.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
type
|
|
2
|
+
type Values,
|
|
3
3
|
ASCII_BANNER_GENERATOR_SERVICE_ID,
|
|
4
4
|
type AsciiBannerGeneratorService,
|
|
5
5
|
ChiselFontAsciiBannerGeneratorService,
|
|
@@ -14,7 +14,7 @@ const banners: SubCommand = {
|
|
|
14
14
|
description: "Demonstrates chisel font ASCII banner and ASCII banner subtitle",
|
|
15
15
|
options: [],
|
|
16
16
|
positionals: [],
|
|
17
|
-
execute: async (context: Context, _argumentValues:
|
|
17
|
+
execute: async (context: Context, _argumentValues: Values): Promise<void> => {
|
|
18
18
|
const printerService = context.getServiceById(PRINTER_SERVICE_ID) as PrinterService;
|
|
19
19
|
const asciiBannerService = context.getServiceById(
|
|
20
20
|
ASCII_BANNER_GENERATOR_SERVICE_ID,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import process from "node:process";
|
|
2
2
|
import {
|
|
3
|
-
type
|
|
3
|
+
type Values,
|
|
4
4
|
COMPLETION_SERVICE_ID,
|
|
5
5
|
type CompletionService,
|
|
6
6
|
type Context,
|
|
@@ -15,7 +15,7 @@ const completion: SubCommand = {
|
|
|
15
15
|
description: "Demonstrates shell completion service",
|
|
16
16
|
options: [],
|
|
17
17
|
positionals: [],
|
|
18
|
-
execute: async (context: Context, _argumentValues:
|
|
18
|
+
execute: async (context: Context, _argumentValues: Values): Promise<void> => {
|
|
19
19
|
const printerService = context.getServiceById(PRINTER_SERVICE_ID) as PrinterService;
|
|
20
20
|
const completionService = context.getServiceById(COMPLETION_SERVICE_ID) as CompletionService;
|
|
21
21
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
type
|
|
2
|
+
type Values,
|
|
3
3
|
type Context,
|
|
4
4
|
KEY_VALUE_SERVICE_ID,
|
|
5
5
|
type KeyValueService,
|
|
@@ -7,34 +7,35 @@ import {
|
|
|
7
7
|
type PrinterService,
|
|
8
8
|
type SubCommand,
|
|
9
9
|
} from "@flowscripter/dynamic-cli-framework";
|
|
10
|
+
import { Secret } from "@flowscripter/dynamic-cli-framework-api";
|
|
10
11
|
|
|
11
12
|
const configuration: SubCommand = {
|
|
12
13
|
name: "configuration",
|
|
13
14
|
description: "Demonstrates secrets storage and key-value service",
|
|
14
15
|
options: [],
|
|
15
16
|
positionals: [],
|
|
16
|
-
async execute(context: Context, _argumentValues:
|
|
17
|
+
async execute(context: Context, _argumentValues: Values): Promise<void> {
|
|
17
18
|
const printerService = context.getServiceById(PRINTER_SERVICE_ID) as PrinterService;
|
|
18
19
|
const keyValueService = context.getServiceById(KEY_VALUE_SERVICE_ID) as KeyValueService;
|
|
19
20
|
|
|
20
21
|
// --- Key-Value Storage ---
|
|
21
22
|
await printerService.print("--- Key-Value Storage ---\n");
|
|
22
23
|
|
|
23
|
-
await keyValueService.
|
|
24
|
-
await keyValueService.
|
|
25
|
-
await keyValueService.
|
|
24
|
+
await keyValueService.set("demo-string", "hello world");
|
|
25
|
+
await keyValueService.set("demo-number", "42");
|
|
26
|
+
await keyValueService.set("demo-json", '{"enabled":true,"retries":3}');
|
|
26
27
|
|
|
27
28
|
const keys = ["demo-string", "demo-number", "demo-json"];
|
|
28
29
|
for (const key of keys) {
|
|
29
|
-
const value = await keyValueService.
|
|
30
|
+
const value = await keyValueService.get(key);
|
|
30
31
|
await printerService.print(` ${key} = ${value}\n`);
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
const missing = await keyValueService.
|
|
34
|
+
const missing = await keyValueService.has("demo-nonexistent");
|
|
34
35
|
await printerService.print(` demo-nonexistent exists: ${missing}\n`);
|
|
35
36
|
|
|
36
37
|
for (const key of keys) {
|
|
37
|
-
await keyValueService.
|
|
38
|
+
await keyValueService.delete(key);
|
|
38
39
|
}
|
|
39
40
|
await printerService.print("Cleaned up keys\n");
|
|
40
41
|
|
|
@@ -42,17 +43,17 @@ const configuration: SubCommand = {
|
|
|
42
43
|
await printerService.print("--- Secret Storage ---\n");
|
|
43
44
|
|
|
44
45
|
try {
|
|
45
|
-
await keyValueService.
|
|
46
|
+
await keyValueService.set("demo-api-key", new Secret("sk-secret-12345"));
|
|
46
47
|
await printerService.print("Stored secret: demo-api-key\n");
|
|
47
48
|
|
|
48
|
-
const exists = await keyValueService.
|
|
49
|
+
const exists = await keyValueService.has("demo-api-key");
|
|
49
50
|
await printerService.print(`Key exists: ${exists}\n`);
|
|
50
51
|
|
|
51
|
-
const secret = await keyValueService.
|
|
52
|
+
const secret = await keyValueService.get<string>("demo-api-key");
|
|
52
53
|
const masked = secret.substring(0, 3) + "***";
|
|
53
54
|
await printerService.print(`Retrieved secret (masked): ${masked}\n`);
|
|
54
55
|
|
|
55
|
-
await keyValueService.
|
|
56
|
+
await keyValueService.delete("demo-api-key");
|
|
56
57
|
await printerService.print("Deleted secret: demo-api-key\n");
|
|
57
58
|
} catch (error) {
|
|
58
59
|
await printerService.warn(
|
package/src/commands/image.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
type
|
|
2
|
+
type Values,
|
|
3
3
|
type Context,
|
|
4
4
|
IMAGE_PRINTER_SERVICE_ID,
|
|
5
5
|
type ImagePrinterService,
|
|
@@ -14,7 +14,7 @@ const image: SubCommand = {
|
|
|
14
14
|
description: "Demonstrates image rendering in the terminal",
|
|
15
15
|
options: [],
|
|
16
16
|
positionals: [],
|
|
17
|
-
execute: async (context: Context, _argumentValues:
|
|
17
|
+
execute: async (context: Context, _argumentValues: Values): Promise<void> => {
|
|
18
18
|
const printerService = context.getServiceById(PRINTER_SERVICE_ID) as PrinterService;
|
|
19
19
|
const imagePrinterService = context.getServiceById(
|
|
20
20
|
IMAGE_PRINTER_SERVICE_ID,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
type
|
|
2
|
+
type Values,
|
|
3
3
|
type Context,
|
|
4
4
|
Icon,
|
|
5
5
|
PRINTER_SERVICE_ID,
|
|
@@ -18,7 +18,7 @@ const interruption: SubCommand = {
|
|
|
18
18
|
description: "Demonstrates graceful shutdown with signal handling (press Ctrl+C to interrupt)",
|
|
19
19
|
options: [],
|
|
20
20
|
positionals: [],
|
|
21
|
-
execute: async (context: Context, _argumentValues:
|
|
21
|
+
execute: async (context: Context, _argumentValues: Values): Promise<void> => {
|
|
22
22
|
const printerService = context.getServiceById(PRINTER_SERVICE_ID) as PrinterService;
|
|
23
23
|
const shutdownService = context.getServiceById(SHUTDOWN_SERVICE_ID) as ShutdownService;
|
|
24
24
|
|
package/src/commands/printing.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Align,
|
|
3
|
-
type
|
|
3
|
+
type Values,
|
|
4
4
|
ASCII_BANNER_GENERATOR_SERVICE_ID,
|
|
5
5
|
type AsciiBannerGeneratorService,
|
|
6
6
|
type Context,
|
|
@@ -31,7 +31,7 @@ const printing: SubCommand = {
|
|
|
31
31
|
description: "Demonstrates printer, tree, table, data dump, and banner output features",
|
|
32
32
|
options: [],
|
|
33
33
|
positionals: [],
|
|
34
|
-
execute: async (context: Context, _argumentValues:
|
|
34
|
+
execute: async (context: Context, _argumentValues: Values): Promise<void> => {
|
|
35
35
|
const printerService = context.getServiceById(PRINTER_SERVICE_ID) as PrinterService;
|
|
36
36
|
const asciiBannerGenerator = context.getServiceById(
|
|
37
37
|
ASCII_BANNER_GENERATOR_SERVICE_ID,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
-
type
|
|
3
|
-
|
|
2
|
+
type Values,
|
|
3
|
+
ValueTypeName,
|
|
4
4
|
type Context,
|
|
5
5
|
PRINTER_SERVICE_ID,
|
|
6
6
|
type PrinterService,
|
|
@@ -19,7 +19,7 @@ const prompting: SubCommand = {
|
|
|
19
19
|
{
|
|
20
20
|
name: "age",
|
|
21
21
|
description: "Your age",
|
|
22
|
-
type:
|
|
22
|
+
type: ValueTypeName.NUMBER,
|
|
23
23
|
shortAlias: "a",
|
|
24
24
|
isOptional: true,
|
|
25
25
|
validate: (value): string | undefined => {
|
|
@@ -35,7 +35,7 @@ const prompting: SubCommand = {
|
|
|
35
35
|
{
|
|
36
36
|
name: "name",
|
|
37
37
|
description: "Your name (must be at least 2 characters)",
|
|
38
|
-
type:
|
|
38
|
+
type: ValueTypeName.STRING,
|
|
39
39
|
validate: (value): string | undefined => {
|
|
40
40
|
const str = value as string;
|
|
41
41
|
if (str.length < 2) {
|
|
@@ -45,7 +45,7 @@ const prompting: SubCommand = {
|
|
|
45
45
|
},
|
|
46
46
|
},
|
|
47
47
|
],
|
|
48
|
-
async execute(context: Context, argumentValues:
|
|
48
|
+
async execute(context: Context, argumentValues: Values): Promise<void> {
|
|
49
49
|
const printerService = context.getServiceById(PRINTER_SERVICE_ID) as PrinterService;
|
|
50
50
|
const prompterService = context.getServiceById(PROMPTER_SERVICE_ID) as PrompterService;
|
|
51
51
|
|