@flowscripter/example-cli 1.1.0 → 1.2.1
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/README.md +2 -5
- package/bun.lock +2 -2
- package/package.json +15 -15
- package/src/commands/arg-parsing.ts +4 -13
- package/src/commands/banners.ts +3 -9
- package/src/commands/completion.ts +4 -14
- package/src/commands/configuration.ts +4 -13
- package/src/commands/demo.ts +1 -4
- package/src/commands/image.ts +3 -12
- package/src/commands/interruption.ts +5 -16
- package/src/commands/printing.ts +10 -34
- package/src/commands/prompting.ts +4 -13
- package/tsconfig.json +4 -1
package/README.md
CHANGED
|
@@ -68,16 +68,13 @@ Compile binary:
|
|
|
68
68
|
|
|
69
69
|
`bun build index.ts --compile --outfile /tmp/example-cli`
|
|
70
70
|
|
|
71
|
-
**NOTE**: The following tasks use Deno as it excels at these and Bun does not
|
|
72
|
-
currently provide such functionality:
|
|
73
|
-
|
|
74
71
|
Format:
|
|
75
72
|
|
|
76
|
-
`
|
|
73
|
+
`bunx oxfmt`
|
|
77
74
|
|
|
78
75
|
Lint:
|
|
79
76
|
|
|
80
|
-
`
|
|
77
|
+
`bunx oxlint index.ts src/ tests/`
|
|
81
78
|
|
|
82
79
|
## Documentation
|
|
83
80
|
|
package/bun.lock
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"": {
|
|
6
6
|
"name": "@flowscripter/example-cli",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@flowscripter/dynamic-cli-framework": "^1.2
|
|
8
|
+
"@flowscripter/dynamic-cli-framework": "^1.3.2",
|
|
9
9
|
},
|
|
10
10
|
"devDependencies": {
|
|
11
11
|
"@types/bun": "^1.3.14",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
},
|
|
18
18
|
"packages": {
|
|
19
|
-
"@flowscripter/dynamic-cli-framework": ["@flowscripter/dynamic-cli-framework@1.2
|
|
19
|
+
"@flowscripter/dynamic-cli-framework": ["@flowscripter/dynamic-cli-framework@1.3.2", "", { "dependencies": { "emphasize": "^7.0.0", "fastest-levenshtein": "^1.0.16", "figlet": "^1.11.0", "highlight.js": "^11.11.1", "prettier": "^3.8.3", "supports-color": "^10.2.2", "supports-terminal-graphics": "^0.1.0" }, "peerDependencies": { "typescript": "^6.0.3" } }, "sha512-t51UUurnjTDaprf9AxHyVto4SV56Q/SdXwm1xfezLQvIj/YVQrJedOSGt+JcZ1MzvcmmX9Gm/SxJNEavv68Z/A=="],
|
|
20
20
|
|
|
21
21
|
"@types/bun": ["@types/bun@1.3.14", "", { "dependencies": { "bun-types": "1.3.14" } }, "sha512-h1hFqFVcvAvD9j9K7ZW7vd82aSA+rTdznZa+5bwvCwqSB1jmmfLcbIWhOLx1/+boy/xmjgCs/OMUL8hRJSmnPw=="],
|
|
22
22
|
|
package/package.json
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flowscripter/example-cli",
|
|
3
|
+
"version": "1.2.1",
|
|
3
4
|
"description": "Simple example CLI using https://github.com/flowscripter/dynamic-cli-framework",
|
|
4
|
-
"homepage": "https://github.com/flowscripter/example-cli#readme",
|
|
5
|
-
"repository": {
|
|
6
|
-
"type": "git",
|
|
7
|
-
"url": "git+https://github.com/flowscripter/example-cli.git"
|
|
8
|
-
},
|
|
9
|
-
"license": "MIT",
|
|
10
5
|
"keywords": [
|
|
11
6
|
"bun",
|
|
7
|
+
"cli",
|
|
8
|
+
"dynamic",
|
|
12
9
|
"example",
|
|
13
|
-
"
|
|
10
|
+
"executable",
|
|
14
11
|
"framework",
|
|
15
|
-
"dynamic",
|
|
16
12
|
"import",
|
|
17
|
-
"
|
|
18
|
-
"cli"
|
|
13
|
+
"plugin"
|
|
19
14
|
],
|
|
20
|
-
"
|
|
15
|
+
"homepage": "https://github.com/flowscripter/example-cli#readme",
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/flowscripter/example-cli.git"
|
|
20
|
+
},
|
|
21
21
|
"type": "module",
|
|
22
|
-
"
|
|
22
|
+
"module": "index.ts",
|
|
23
23
|
"publishConfig": {
|
|
24
24
|
"access": "public"
|
|
25
25
|
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@flowscripter/dynamic-cli-framework": "^1.3.2"
|
|
28
|
+
},
|
|
26
29
|
"devDependencies": {
|
|
27
30
|
"@types/bun": "^1.3.14"
|
|
28
31
|
},
|
|
29
32
|
"peerDependencies": {
|
|
30
33
|
"typescript": "^6.0.3"
|
|
31
|
-
},
|
|
32
|
-
"dependencies": {
|
|
33
|
-
"@flowscripter/dynamic-cli-framework": "^1.2.0"
|
|
34
34
|
}
|
|
35
35
|
}
|
|
@@ -12,8 +12,7 @@ import {
|
|
|
12
12
|
|
|
13
13
|
const argParsing: SubCommand = {
|
|
14
14
|
name: "arg-parsing",
|
|
15
|
-
description:
|
|
16
|
-
"Demonstrates argument parsing, types, validation, and syntax-highlighted output",
|
|
15
|
+
description: "Demonstrates argument parsing, types, validation, and syntax-highlighted output",
|
|
17
16
|
options: [
|
|
18
17
|
{
|
|
19
18
|
name: "booleanOption",
|
|
@@ -115,22 +114,14 @@ const argParsing: SubCommand = {
|
|
|
115
114
|
],
|
|
116
115
|
},
|
|
117
116
|
],
|
|
118
|
-
async execute(
|
|
119
|
-
context
|
|
120
|
-
argumentValues: ArgumentValues,
|
|
121
|
-
): Promise<void> {
|
|
122
|
-
const printerService = context.getServiceById(
|
|
123
|
-
PRINTER_SERVICE_ID,
|
|
124
|
-
) as PrinterService;
|
|
117
|
+
async execute(context: Context, argumentValues: ArgumentValues): Promise<void> {
|
|
118
|
+
const printerService = context.getServiceById(PRINTER_SERVICE_ID) as PrinterService;
|
|
125
119
|
const highlighterService = context.getServiceById(
|
|
126
120
|
SYNTAX_HIGHLIGHTER_SERVICE_ID,
|
|
127
121
|
) as SyntaxHighlighterService;
|
|
128
122
|
|
|
129
123
|
await printerService.print(
|
|
130
|
-
highlighterService.highlight(
|
|
131
|
-
JSON.stringify(argumentValues, null, 2),
|
|
132
|
-
"json",
|
|
133
|
-
) + "\n",
|
|
124
|
+
highlighterService.highlight(JSON.stringify(argumentValues, null, 2), "json") + "\n",
|
|
134
125
|
);
|
|
135
126
|
},
|
|
136
127
|
};
|
package/src/commands/banners.ts
CHANGED
|
@@ -11,17 +11,11 @@ import {
|
|
|
11
11
|
|
|
12
12
|
const banners: SubCommand = {
|
|
13
13
|
name: "banners",
|
|
14
|
-
description:
|
|
15
|
-
"Demonstrates chisel font ASCII banner and ASCII banner subtitle",
|
|
14
|
+
description: "Demonstrates chisel font ASCII banner and ASCII banner subtitle",
|
|
16
15
|
options: [],
|
|
17
16
|
positionals: [],
|
|
18
|
-
execute: async (
|
|
19
|
-
context
|
|
20
|
-
_argumentValues: ArgumentValues,
|
|
21
|
-
): Promise<void> => {
|
|
22
|
-
const printerService = context.getServiceById(
|
|
23
|
-
PRINTER_SERVICE_ID,
|
|
24
|
-
) as PrinterService;
|
|
17
|
+
execute: async (context: Context, _argumentValues: ArgumentValues): Promise<void> => {
|
|
18
|
+
const printerService = context.getServiceById(PRINTER_SERVICE_ID) as PrinterService;
|
|
25
19
|
const asciiBannerService = context.getServiceById(
|
|
26
20
|
ASCII_BANNER_GENERATOR_SERVICE_ID,
|
|
27
21
|
) as AsciiBannerGeneratorService;
|
|
@@ -14,21 +14,11 @@ const completion: SubCommand = {
|
|
|
14
14
|
description: "Demonstrates shell completion service",
|
|
15
15
|
options: [],
|
|
16
16
|
positionals: [],
|
|
17
|
-
execute: async (
|
|
18
|
-
context
|
|
19
|
-
|
|
20
|
-
): Promise<void> => {
|
|
21
|
-
const printerService = context.getServiceById(
|
|
22
|
-
PRINTER_SERVICE_ID,
|
|
23
|
-
) as PrinterService;
|
|
24
|
-
const completionService = context.getServiceById(
|
|
25
|
-
COMPLETION_SERVICE_ID,
|
|
26
|
-
) as CompletionService;
|
|
17
|
+
execute: async (context: Context, _argumentValues: ArgumentValues): Promise<void> => {
|
|
18
|
+
const printerService = context.getServiceById(PRINTER_SERVICE_ID) as PrinterService;
|
|
19
|
+
const completionService = context.getServiceById(COMPLETION_SERVICE_ID) as CompletionService;
|
|
27
20
|
|
|
28
|
-
const bootstrapScript = completionService.getBootstrapScript(
|
|
29
|
-
ShellType.BASH,
|
|
30
|
-
"example-cli",
|
|
31
|
-
);
|
|
21
|
+
const bootstrapScript = completionService.getBootstrapScript(ShellType.BASH, "example-cli");
|
|
32
22
|
await printerService.print(`Bash bootstrap script:\n${bootstrapScript}\n`);
|
|
33
23
|
|
|
34
24
|
const configPath = completionService.getDefaultConfigPath(ShellType.BASH);
|
|
@@ -13,16 +13,9 @@ const configuration: SubCommand = {
|
|
|
13
13
|
description: "Demonstrates secrets storage and key-value service",
|
|
14
14
|
options: [],
|
|
15
15
|
positionals: [],
|
|
16
|
-
async execute(
|
|
17
|
-
context
|
|
18
|
-
|
|
19
|
-
): Promise<void> {
|
|
20
|
-
const printerService = context.getServiceById(
|
|
21
|
-
PRINTER_SERVICE_ID,
|
|
22
|
-
) as PrinterService;
|
|
23
|
-
const keyValueService = context.getServiceById(
|
|
24
|
-
KEY_VALUE_SERVICE_ID,
|
|
25
|
-
) as KeyValueService;
|
|
16
|
+
async execute(context: Context, _argumentValues: ArgumentValues): Promise<void> {
|
|
17
|
+
const printerService = context.getServiceById(PRINTER_SERVICE_ID) as PrinterService;
|
|
18
|
+
const keyValueService = context.getServiceById(KEY_VALUE_SERVICE_ID) as KeyValueService;
|
|
26
19
|
|
|
27
20
|
// --- Key-Value Storage ---
|
|
28
21
|
await printerService.print("--- Key-Value Storage ---\n");
|
|
@@ -63,9 +56,7 @@ const configuration: SubCommand = {
|
|
|
63
56
|
await printerService.print("Deleted secret: demo-api-key\n");
|
|
64
57
|
} catch (error) {
|
|
65
58
|
await printerService.warn(
|
|
66
|
-
`Secret storage unavailable (OS keyring may be locked): ${
|
|
67
|
-
(error as Error).message
|
|
68
|
-
}\n`,
|
|
59
|
+
`Secret storage unavailable (OS keyring may be locked): ${(error as Error).message}\n`,
|
|
69
60
|
);
|
|
70
61
|
}
|
|
71
62
|
},
|
package/src/commands/demo.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type Context,
|
|
3
|
-
type GroupCommand,
|
|
4
|
-
} from "@flowscripter/dynamic-cli-framework";
|
|
1
|
+
import { type Context, type GroupCommand } from "@flowscripter/dynamic-cli-framework";
|
|
5
2
|
import printing from "./printing.ts";
|
|
6
3
|
import prompting from "./prompting.ts";
|
|
7
4
|
import argParsing from "./arg-parsing.ts";
|
package/src/commands/image.ts
CHANGED
|
@@ -15,13 +15,8 @@ const image: SubCommand = {
|
|
|
15
15
|
description: "Demonstrates image rendering in the terminal",
|
|
16
16
|
options: [],
|
|
17
17
|
positionals: [],
|
|
18
|
-
execute: async (
|
|
19
|
-
context
|
|
20
|
-
_argumentValues: ArgumentValues,
|
|
21
|
-
): Promise<void> => {
|
|
22
|
-
const printerService = context.getServiceById(
|
|
23
|
-
PRINTER_SERVICE_ID,
|
|
24
|
-
) as PrinterService;
|
|
18
|
+
execute: async (context: Context, _argumentValues: ArgumentValues): Promise<void> => {
|
|
19
|
+
const printerService = context.getServiceById(PRINTER_SERVICE_ID) as PrinterService;
|
|
25
20
|
const imagePrinterService = context.getServiceById(
|
|
26
21
|
IMAGE_PRINTER_SERVICE_ID,
|
|
27
22
|
) as ImagePrinterService;
|
|
@@ -33,11 +28,7 @@ const image: SubCommand = {
|
|
|
33
28
|
imagePath = path.join(import.meta.dir, "..", "..", "assets", "logo.png");
|
|
34
29
|
}
|
|
35
30
|
const imageBuffer = await Bun.file(imagePath).bytes();
|
|
36
|
-
const imageOutput = await imagePrinterService.image(
|
|
37
|
-
imageBuffer,
|
|
38
|
-
25,
|
|
39
|
-
"#FFFFFF",
|
|
40
|
-
);
|
|
31
|
+
const imageOutput = await imagePrinterService.image(imageBuffer, 25, "#FFFFFF");
|
|
41
32
|
await printerService.print(imageOutput + "\n");
|
|
42
33
|
},
|
|
43
34
|
};
|
|
@@ -15,20 +15,12 @@ async function sleep(seconds: number): Promise<void> {
|
|
|
15
15
|
|
|
16
16
|
const interruption: SubCommand = {
|
|
17
17
|
name: "interruption",
|
|
18
|
-
description:
|
|
19
|
-
"Demonstrates graceful shutdown with signal handling (press Ctrl+C to interrupt)",
|
|
18
|
+
description: "Demonstrates graceful shutdown with signal handling (press Ctrl+C to interrupt)",
|
|
20
19
|
options: [],
|
|
21
20
|
positionals: [],
|
|
22
|
-
execute: async (
|
|
23
|
-
context
|
|
24
|
-
|
|
25
|
-
): Promise<void> => {
|
|
26
|
-
const printerService = context.getServiceById(
|
|
27
|
-
PRINTER_SERVICE_ID,
|
|
28
|
-
) as PrinterService;
|
|
29
|
-
const shutdownService = context.getServiceById(
|
|
30
|
-
SHUTDOWN_SERVICE_ID,
|
|
31
|
-
) as ShutdownService;
|
|
21
|
+
execute: async (context: Context, _argumentValues: ArgumentValues): Promise<void> => {
|
|
22
|
+
const printerService = context.getServiceById(PRINTER_SERVICE_ID) as PrinterService;
|
|
23
|
+
const shutdownService = context.getServiceById(SHUTDOWN_SERVICE_ID) as ShutdownService;
|
|
32
24
|
|
|
33
25
|
await printerService.print(
|
|
34
26
|
"Entering long-running mode. Press Ctrl+C to request graceful shutdown...\n",
|
|
@@ -42,10 +34,7 @@ const interruption: SubCommand = {
|
|
|
42
34
|
|
|
43
35
|
if (shutdownService.isShutdownRequested) {
|
|
44
36
|
await printerService.hideSpinner();
|
|
45
|
-
await printerService.print(
|
|
46
|
-
"Shutdown requested, finishing gracefully...\n",
|
|
47
|
-
Icon.ALERT,
|
|
48
|
-
);
|
|
37
|
+
await printerService.print("Shutdown requested, finishing gracefully...\n", Icon.ALERT);
|
|
49
38
|
break;
|
|
50
39
|
}
|
|
51
40
|
}
|
package/src/commands/printing.ts
CHANGED
|
@@ -28,17 +28,11 @@ async function sleep(seconds: number): Promise<void> {
|
|
|
28
28
|
|
|
29
29
|
const printing: SubCommand = {
|
|
30
30
|
name: "printing",
|
|
31
|
-
description:
|
|
32
|
-
"Demonstrates printer, tree, table, data dump, and banner output features",
|
|
31
|
+
description: "Demonstrates printer, tree, table, data dump, and banner output features",
|
|
33
32
|
options: [],
|
|
34
33
|
positionals: [],
|
|
35
|
-
execute: async (
|
|
36
|
-
context
|
|
37
|
-
_argumentValues: ArgumentValues,
|
|
38
|
-
): Promise<void> => {
|
|
39
|
-
const printerService = context.getServiceById(
|
|
40
|
-
PRINTER_SERVICE_ID,
|
|
41
|
-
) as PrinterService;
|
|
34
|
+
execute: async (context: Context, _argumentValues: ArgumentValues): Promise<void> => {
|
|
35
|
+
const printerService = context.getServiceById(PRINTER_SERVICE_ID) as PrinterService;
|
|
42
36
|
const asciiBannerGenerator = context.getServiceById(
|
|
43
37
|
ASCII_BANNER_GENERATOR_SERVICE_ID,
|
|
44
38
|
) as AsciiBannerGeneratorService;
|
|
@@ -74,12 +68,7 @@ const printing: SubCommand = {
|
|
|
74
68
|
|
|
75
69
|
await sleep(0.5);
|
|
76
70
|
|
|
77
|
-
const handle1 = await printerService.showProgressBar(
|
|
78
|
-
"sec",
|
|
79
|
-
"Waiting 3 seconds",
|
|
80
|
-
3,
|
|
81
|
-
0,
|
|
82
|
-
);
|
|
71
|
+
const handle1 = await printerService.showProgressBar("sec", "Waiting 3 seconds", 3, 0);
|
|
83
72
|
await sleep(1);
|
|
84
73
|
printerService.updateProgressBar(handle1, 1);
|
|
85
74
|
await sleep(1);
|
|
@@ -119,21 +108,11 @@ const printing: SubCommand = {
|
|
|
119
108
|
|
|
120
109
|
// --- Colors ---
|
|
121
110
|
await printerService.print("--- Colors ---\n");
|
|
122
|
-
await printerService.print(
|
|
123
|
-
|
|
124
|
-
);
|
|
125
|
-
await printerService.print(
|
|
126
|
-
|
|
127
|
-
);
|
|
128
|
-
await printerService.print(
|
|
129
|
-
printerService.backgroundBlue("Background Blue") + "\n",
|
|
130
|
-
);
|
|
131
|
-
await printerService.print(
|
|
132
|
-
printerService.backgroundGreen("Background Green") + "\n",
|
|
133
|
-
);
|
|
134
|
-
await printerService.print(
|
|
135
|
-
printerService.backgroundCyan("Background Cyan") + "\n",
|
|
136
|
-
);
|
|
111
|
+
await printerService.print(printerService.green("Green text") + "\n");
|
|
112
|
+
await printerService.print(printerService.backgroundRed("Background Red") + "\n");
|
|
113
|
+
await printerService.print(printerService.backgroundBlue("Background Blue") + "\n");
|
|
114
|
+
await printerService.print(printerService.backgroundGreen("Background Green") + "\n");
|
|
115
|
+
await printerService.print(printerService.backgroundCyan("Background Cyan") + "\n");
|
|
137
116
|
await printerService.print(
|
|
138
117
|
printerService.backgroundColor("Custom Hex Background", "#FF6600") + "\n",
|
|
139
118
|
);
|
|
@@ -141,10 +120,7 @@ const printing: SubCommand = {
|
|
|
141
120
|
// --- Hyperlink ---
|
|
142
121
|
await printerService.print("--- Hyperlink ---\n");
|
|
143
122
|
await printerService.print(
|
|
144
|
-
printerService.hyperlink(
|
|
145
|
-
"Flowscripter on GitHub",
|
|
146
|
-
"https://github.com/flowscripter",
|
|
147
|
-
) + "\n",
|
|
123
|
+
printerService.hyperlink("Flowscripter on GitHub", "https://github.com/flowscripter") + "\n",
|
|
148
124
|
);
|
|
149
125
|
|
|
150
126
|
// --- ASCII Banner ---
|
|
@@ -45,16 +45,9 @@ const prompting: SubCommand = {
|
|
|
45
45
|
},
|
|
46
46
|
},
|
|
47
47
|
],
|
|
48
|
-
async execute(
|
|
49
|
-
context
|
|
50
|
-
|
|
51
|
-
): Promise<void> {
|
|
52
|
-
const printerService = context.getServiceById(
|
|
53
|
-
PRINTER_SERVICE_ID,
|
|
54
|
-
) as PrinterService;
|
|
55
|
-
const prompterService = context.getServiceById(
|
|
56
|
-
PROMPTER_SERVICE_ID,
|
|
57
|
-
) as PrompterService;
|
|
48
|
+
async execute(context: Context, argumentValues: ArgumentValues): Promise<void> {
|
|
49
|
+
const printerService = context.getServiceById(PRINTER_SERVICE_ID) as PrinterService;
|
|
50
|
+
const prompterService = context.getServiceById(PROMPTER_SERVICE_ID) as PrompterService;
|
|
58
51
|
|
|
59
52
|
await printerService.print(
|
|
60
53
|
"Argument values: " + JSON.stringify(argumentValues, null, 2) + "\n",
|
|
@@ -111,9 +104,7 @@ const prompting: SubCommand = {
|
|
|
111
104
|
|
|
112
105
|
await printerService.print("Prompt results:\n");
|
|
113
106
|
for (const result of results) {
|
|
114
|
-
await printerService.print(
|
|
115
|
-
` ${result.name}: ${JSON.stringify(result.value)}\n`,
|
|
116
|
-
);
|
|
107
|
+
await printerService.print(` ${result.name}: ${JSON.stringify(result.value)}\n`);
|
|
117
108
|
}
|
|
118
109
|
},
|
|
119
110
|
};
|
package/tsconfig.json
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
"jsx": "react-jsx",
|
|
9
9
|
"allowJs": true,
|
|
10
10
|
|
|
11
|
+
"types": ["bun", "node"],
|
|
12
|
+
|
|
11
13
|
// Bundler mode
|
|
12
14
|
"moduleResolution": "bundler",
|
|
13
15
|
"allowImportingTsExtensions": true,
|
|
@@ -23,5 +25,6 @@
|
|
|
23
25
|
"noUnusedLocals": false,
|
|
24
26
|
"noUnusedParameters": false,
|
|
25
27
|
"noPropertyAccessFromIndexSignature": false
|
|
26
|
-
}
|
|
28
|
+
},
|
|
29
|
+
"exclude": ["tests"]
|
|
27
30
|
}
|