@flowscripter/example-cli 3.0.11 → 3.1.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 +1 -0
- package/functional_tests/features/executable.feature +3 -0
- package/package.json +3 -2
- package/src/cli.ts +2 -0
- package/src/commands/printing.ts +22 -0
package/bun.lock
CHANGED
|
@@ -17,6 +17,9 @@ Feature: Executable
|
|
|
17
17
|
And the executable should have output "--- Tree ---"
|
|
18
18
|
And the executable should have output "--- Table ---"
|
|
19
19
|
And the executable should have output "--- Data Dump ---"
|
|
20
|
+
And the executable should have output "--- Pretty Printing: JSON (built-in syntax) ---"
|
|
21
|
+
And the executable should have output "--- Pretty Printing: YAML (added syntax) ---"
|
|
22
|
+
And the executable should have output "enabled: true"
|
|
20
23
|
|
|
21
24
|
Scenario: Argument parsing demo
|
|
22
25
|
When the executable is launched with "demo:arg-parsing true 1 hello"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flowscripter/example-cli",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Simple example CLI using https://github.com/flowscripter/dynamic-cli-framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bun",
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@flowscripter/dynamic-cli-framework": "^9.0.2",
|
|
28
28
|
"@flowscripter/dynamic-cli-framework-api": "^5.0.0",
|
|
29
|
-
"@flowscripter/dynamic-plugin-framework": "2.2.19"
|
|
29
|
+
"@flowscripter/dynamic-plugin-framework": "2.2.19",
|
|
30
|
+
"prettier": "^3.9.9"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
33
|
"@types/bun": "^1.4.2",
|
package/src/cli.ts
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
createBannerStartupTask,
|
|
4
4
|
DataDumpGeneratorServiceProvider,
|
|
5
5
|
launchMultiCommandCLI,
|
|
6
|
+
PrettyPrinterServiceProvider,
|
|
6
7
|
SyntaxHighlighterServiceProvider,
|
|
7
8
|
TreePrinterServiceProvider,
|
|
8
9
|
} from "@flowscripter/dynamic-cli-framework";
|
|
@@ -23,6 +24,7 @@ export async function cli(): Promise<void> {
|
|
|
23
24
|
[
|
|
24
25
|
new AsciiBannerGeneratorServiceProvider(45),
|
|
25
26
|
new SyntaxHighlighterServiceProvider(40),
|
|
27
|
+
new PrettyPrinterServiceProvider(38),
|
|
26
28
|
new TreePrinterServiceProvider(35),
|
|
27
29
|
new DataDumpGeneratorServiceProvider(30),
|
|
28
30
|
],
|
package/src/commands/printing.ts
CHANGED
|
@@ -8,7 +8,9 @@ import {
|
|
|
8
8
|
type DataDumpGeneratorService,
|
|
9
9
|
DumpFormat,
|
|
10
10
|
Icon,
|
|
11
|
+
PRETTY_PRINTER_SERVICE_ID,
|
|
11
12
|
PRINTER_SERVICE_ID,
|
|
13
|
+
type PrettyPrinterService,
|
|
12
14
|
type PrinterService,
|
|
13
15
|
ProgressStyle,
|
|
14
16
|
SpinnerStyle,
|
|
@@ -21,6 +23,7 @@ import {
|
|
|
21
23
|
type TreePrinterService,
|
|
22
24
|
} from "@flowscripter/dynamic-cli-framework";
|
|
23
25
|
import { Buffer } from "node:buffer";
|
|
26
|
+
import * as yaml from "prettier/plugins/yaml";
|
|
24
27
|
|
|
25
28
|
async function sleep(seconds: number): Promise<void> {
|
|
26
29
|
await new Promise((resolve) => setTimeout(resolve, seconds * 1000));
|
|
@@ -45,6 +48,9 @@ const printing: SubCommand = {
|
|
|
45
48
|
const dataDumpGeneratorService = context.getServiceById(
|
|
46
49
|
DATA_DUMP_GENERATOR_SERVICE_ID,
|
|
47
50
|
) as DataDumpGeneratorService;
|
|
51
|
+
const prettyPrinterService = context.getServiceById(
|
|
52
|
+
PRETTY_PRINTER_SERVICE_ID,
|
|
53
|
+
) as PrettyPrinterService;
|
|
48
54
|
|
|
49
55
|
// --- Basic Printer ---
|
|
50
56
|
await printerService.print("--- Basic Printer ---\n");
|
|
@@ -73,6 +79,7 @@ const printing: SubCommand = {
|
|
|
73
79
|
total: 3,
|
|
74
80
|
current: 0,
|
|
75
81
|
format: (value) => `${value}sec`,
|
|
82
|
+
formatRate: (rate) => `${rate.toFixed(1)}sec/s`,
|
|
76
83
|
});
|
|
77
84
|
await sleep(1);
|
|
78
85
|
printerService.updateProgressBar(handle1, 1);
|
|
@@ -102,6 +109,7 @@ const printing: SubCommand = {
|
|
|
102
109
|
current: 0,
|
|
103
110
|
style: ProgressStyle.FILL,
|
|
104
111
|
format: (value) => `${value}sec`,
|
|
112
|
+
formatRate: (rate) => `${rate.toFixed(1)}sec/s`,
|
|
105
113
|
});
|
|
106
114
|
await sleep(1);
|
|
107
115
|
printerService.updateProgressBar(handle2, 1);
|
|
@@ -192,6 +200,20 @@ const printing: SubCommand = {
|
|
|
192
200
|
format: DumpFormat.HEX,
|
|
193
201
|
});
|
|
194
202
|
await printerService.print(hexDump + "\n");
|
|
203
|
+
|
|
204
|
+
// --- Pretty Printing: JSON (built-in syntax) ---
|
|
205
|
+
await printerService.print("--- Pretty Printing: JSON (built-in syntax) ---\n");
|
|
206
|
+
const json = '{"name":"example-cli","tags":["cli","demo"],"nested":{"enabled":true,"count":3}}';
|
|
207
|
+
await printerService.print(await prettyPrinterService.prettify(json, "json"));
|
|
208
|
+
|
|
209
|
+
// --- Pretty Printing: YAML (added syntax) ---
|
|
210
|
+
await printerService.print("--- Pretty Printing: YAML (added syntax) ---\n");
|
|
211
|
+
if (!(await prettyPrinterService.getRegisteredSyntaxes()).includes("yaml")) {
|
|
212
|
+
await prettyPrinterService.registerSyntax("yaml", yaml);
|
|
213
|
+
}
|
|
214
|
+
const yamlText =
|
|
215
|
+
"name: example-cli\ntags: [cli, demo]\nnested: {enabled: true, count: 3}\n";
|
|
216
|
+
await printerService.print(await prettyPrinterService.prettify(yamlText, "yaml"));
|
|
195
217
|
},
|
|
196
218
|
};
|
|
197
219
|
|