@flowscripter/example-cli 3.0.11 → 3.1.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/bun.lock CHANGED
@@ -5,9 +5,10 @@
5
5
  "": {
6
6
  "name": "@flowscripter/example-cli",
7
7
  "dependencies": {
8
- "@flowscripter/dynamic-cli-framework": "^9.0.2",
8
+ "@flowscripter/dynamic-cli-framework": "^9.0.3",
9
9
  "@flowscripter/dynamic-cli-framework-api": "^5.0.0",
10
10
  "@flowscripter/dynamic-plugin-framework": "2.2.19",
11
+ "prettier": "^3.9.9",
11
12
  },
12
13
  "devDependencies": {
13
14
  "@types/bun": "^1.4.2",
@@ -21,7 +22,7 @@
21
22
  },
22
23
  },
23
24
  "packages": {
24
- "@flowscripter/dynamic-cli-framework": ["@flowscripter/dynamic-cli-framework@9.0.2", "", { "dependencies": { "@flowscripter/dynamic-cli-framework-api": "^5.0.0", "@flowscripter/dynamic-plugin-framework": "^2.2.16", "emphasize": "^7.0.0", "fastest-levenshtein": "^1.0.16", "figlet": "^1.12.0", "highlight.js": "^11.12.0", "prettier": "^3.9.9", "semver": "^7.8.5", "supports-color": "^11.0.0", "supports-terminal-graphics": "^0.1.0" }, "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-+MGIrRQLUOX+ot47+a2vZU6PhbHnaHz3DrpeX9iwUlQXup8SV6wNBPZCCGIG2fUfrIf87WqoaSXXYoeJGXsG4g=="],
25
+ "@flowscripter/dynamic-cli-framework": ["@flowscripter/dynamic-cli-framework@9.0.3", "", { "dependencies": { "@flowscripter/dynamic-cli-framework-api": "^5.0.0", "@flowscripter/dynamic-plugin-framework": "^2.2.16", "emphasize": "^7.0.0", "fastest-levenshtein": "^1.0.16", "figlet": "^1.12.0", "highlight.js": "^11.12.0", "prettier": "^3.9.9", "semver": "^7.8.5", "supports-color": "^11.0.0", "supports-terminal-graphics": "^0.1.0" }, "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-Oh8kl4g+LqIx0dMdgFYlUNc8a+RDSueij4HMQb6ySOmM6EYWPOcMvvHylieH/eDSKqdcIu5LznPQwgHOcgPtLQ=="],
25
26
 
26
27
  "@flowscripter/dynamic-cli-framework-api": ["@flowscripter/dynamic-cli-framework-api@5.0.0", "", { "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-mF2V1Np+MKSQqeXGJO8WWT2dNiVlAKg1gFrf+lPriWBXLZFyv9JU44gDYtCMfenQuoaHMb3IgOwIfVeBclvYhQ=="],
27
28
 
@@ -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.11",
3
+ "version": "3.1.1",
4
4
  "description": "Simple example CLI using https://github.com/flowscripter/dynamic-cli-framework",
5
5
  "keywords": [
6
6
  "bun",
@@ -24,9 +24,10 @@
24
24
  "access": "public"
25
25
  },
26
26
  "dependencies": {
27
- "@flowscripter/dynamic-cli-framework": "^9.0.2",
27
+ "@flowscripter/dynamic-cli-framework": "^9.0.3",
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
  ],
@@ -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