@flowscripter/dynamic-cli-framework 1.2.1 → 1.3.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.
Files changed (166) hide show
  1. package/README/core-service-providers.md +2 -2
  2. package/README/development.md +3 -6
  3. package/README/implementation-details.md +17 -17
  4. package/README/key-concepts.md +17 -17
  5. package/README.md +4 -4
  6. package/bun.lock +0 -2
  7. package/index.ts +22 -30
  8. package/package.json +19 -19
  9. package/src/api/argument/Argument.ts +1 -1
  10. package/src/api/argument/ArgumentValueTypes.ts +3 -10
  11. package/src/api/argument/ComplexOption.ts +5 -9
  12. package/src/api/command/GlobalCommand.ts +1 -4
  13. package/src/api/service/core/ArgumentPrompterService.ts +1 -3
  14. package/src/api/service/core/AsciiBannerGeneratorService.ts +1 -4
  15. package/src/api/service/core/CompletionService.ts +2 -6
  16. package/src/api/service/core/ImagePrinterService.ts +1 -2
  17. package/src/api/service/core/KeyValueService.ts +1 -2
  18. package/src/api/service/core/PrettyPrinterService.ts +1 -4
  19. package/src/api/service/core/PrinterService.ts +8 -9
  20. package/src/api/service/core/PrompterService.ts +4 -11
  21. package/src/api/service/core/ShutdownService.ts +1 -2
  22. package/src/api/service/core/SyntaxHighlighterService.ts +1 -5
  23. package/src/api/service/core/Table.ts +7 -25
  24. package/src/api/service/core/TreePrinterService.ts +1 -2
  25. package/src/cli/BaseCLI.ts +17 -47
  26. package/src/cli/DefaultRuntimeCLI.ts +1 -4
  27. package/src/command/CompletionCommand.ts +19 -45
  28. package/src/command/MultiCommandCliHelpCommand.ts +45 -92
  29. package/src/command/SingleCommandCliHelpCommand.ts +17 -28
  30. package/src/command/UsageCommand.ts +6 -12
  31. package/src/command/VersionCommand.ts +2 -6
  32. package/src/launcher.ts +4 -2
  33. package/src/runtime/DefaultContext.ts +2 -5
  34. package/src/runtime/argument/ArgumentTypeGuards.ts +1 -3
  35. package/src/runtime/command/CommandTypeGuards.ts +5 -14
  36. package/src/runtime/command/CommandValidator.ts +56 -118
  37. package/src/runtime/parser.ts +13 -17
  38. package/src/runtime/registry/CommandRegistry.ts +2 -7
  39. package/src/runtime/registry/DefaultCommandRegistry.ts +32 -84
  40. package/src/runtime/registry/DefaultServiceProviderRegistry.ts +3 -9
  41. package/src/runtime/runner.ts +103 -142
  42. package/src/runtime/scanner.ts +28 -46
  43. package/src/runtime/values/ValuePopulationResult.ts +1 -2
  44. package/src/runtime/values/argumentValueMerge.ts +16 -28
  45. package/src/runtime/values/argumentValueValidation.ts +21 -67
  46. package/src/runtime/values/globalCommandValuePopulation.ts +9 -18
  47. package/src/runtime/values/subCommandValuePopulation.ts +42 -65
  48. package/src/service/argumentPrompter/ArgumentPrompterServiceProvider.ts +3 -10
  49. package/src/service/argumentPrompter/DefaultArgumentPrompterService.ts +22 -59
  50. package/src/service/asciiBannerGenerator/AsciiBannerGeneratorServiceProvider.ts +5 -14
  51. package/src/service/asciiBannerGenerator/DefaultAsciiBannerGeneratorService.ts +59 -77
  52. package/src/service/banner/BannerServiceProvider.ts +13 -35
  53. package/src/service/banner/command/NoBannerCommand.ts +2 -8
  54. package/src/service/chiselAsciiBannerGenerator/ChiselFontAsciiBannerGeneratorService.ts +5 -10
  55. package/src/service/completion/CompletionServiceProvider.ts +20 -48
  56. package/src/service/completion/DefaultCompletionService.ts +17 -56
  57. package/src/service/completion/shell/ShellHandler.ts +1 -3
  58. package/src/service/completion/shell/fish.ts +1 -1
  59. package/src/service/completion/shell/powershell.ts +2 -12
  60. package/src/service/completion/shell/zsh.ts +1 -1
  61. package/src/service/configuration/ConfigurationServiceProvider.ts +40 -133
  62. package/src/service/configuration/DefaultKeyValueService.ts +6 -20
  63. package/src/service/configuration/DefaultSecretService.ts +10 -14
  64. package/src/service/configuration/command/ConfigCommand.ts +1 -4
  65. package/src/service/configuration/command/DumpConfigCommand.ts +9 -21
  66. package/src/service/dataDumpGenerator/DataDumpGeneratorServiceProvider.ts +5 -14
  67. package/src/service/dataDumpGenerator/DefaultDataDumpGeneratorService.ts +5 -12
  68. package/src/service/imagePrinter/DefaultImagePrinterService.ts +1 -5
  69. package/src/service/imagePrinter/ImagePrinterServiceProvider.ts +1 -4
  70. package/src/service/prettyPrinter/DefaultPrettyPrinterService.ts +4 -12
  71. package/src/service/prettyPrinter/PrettyPrinterServiceProvider.ts +3 -10
  72. package/src/service/printer/DefaultPrinterService.ts +20 -83
  73. package/src/service/printer/PrinterServiceProvider.ts +3 -11
  74. package/src/service/printer/command/DarkModeCommand.ts +3 -10
  75. package/src/service/printer/command/LogLevelCommand.ts +7 -26
  76. package/src/service/printer/command/NoColorCommand.ts +3 -10
  77. package/src/service/printer/command/NoHyperlinksCommand.ts +3 -10
  78. package/src/service/printer/terminal/Progress.ts +99 -90
  79. package/src/service/printer/terminal/Spinner.ts +7 -26
  80. package/src/service/prompter/DefaultPrompterService.ts +2 -6
  81. package/src/service/prompter/PrompterServiceProvider.ts +3 -11
  82. package/src/service/prompter/command/NoPromptCommand.ts +3 -10
  83. package/src/service/prompter/prompt/PromptContext.ts +5 -18
  84. package/src/service/prompter/prompt/promptMultiSelect.ts +6 -21
  85. package/src/service/prompter/prompt/promptOpenUrl.ts +7 -22
  86. package/src/service/prompter/prompt/promptSingleSelect.ts +6 -23
  87. package/src/service/prompter/prompt/promptText.ts +10 -27
  88. package/src/service/prompter/prompt/promptToggle.ts +8 -8
  89. package/src/service/shutdown/ShutdownServiceProvider.ts +3 -10
  90. package/src/service/syntaxHighlighter/DefaultSyntaxHighlighterService.ts +13 -26
  91. package/src/service/syntaxHighlighter/SyntaxHighlighterServiceProvider.ts +8 -21
  92. package/src/service/tableGenerator/DefaultTableGeneratorService.ts +44 -68
  93. package/src/service/tableGenerator/TableGeneratorServiceProvider.ts +7 -16
  94. package/src/service/treePrinter/DefaultTreePrinterService.ts +2 -7
  95. package/src/service/treePrinter/TreePrinterServiceProvider.ts +4 -12
  96. package/src/terminal/ImageRenderer.ts +35 -54
  97. package/src/terminal/PngDecoder.ts +10 -19
  98. package/src/terminal/TtyStyler.ts +11 -9
  99. package/src/terminal/TtyTerminal.ts +2 -10
  100. package/src/terminal/supportsHyperlinks.ts +4 -10
  101. package/src/util/configHelper.ts +3 -10
  102. package/src/util/envVarHelper.ts +50 -88
  103. package/src/util/helpHelper.ts +123 -193
  104. package/src/util/logger.ts +12 -42
  105. package/src/util/runnerHelper.ts +20 -61
  106. package/tests/cli/BaseCLI.test.ts +23 -80
  107. package/tests/command/CompletionCommand.test.ts +1 -6
  108. package/tests/command/MultiCommandCliHelpCommand.test.ts +51 -205
  109. package/tests/command/SingleCommandCliHelpCommand.test.ts +21 -103
  110. package/tests/command/UsageCommand.test.ts +4 -10
  111. package/tests/fixtures/Command.ts +87 -68
  112. package/tests/fixtures/CommandRegistry.ts +1 -3
  113. package/tests/fixtures/Context.ts +3 -11
  114. package/tests/fixtures/ServiceProviderRegistry.ts +1 -1
  115. package/tests/fixtures/prettierPluginFoo.ts +1 -1
  116. package/tests/fixtures/util.ts +2 -8
  117. package/tests/runtime/argument/ArgumentTypeGuards.test.ts +1 -3
  118. package/tests/runtime/command/CommandValidator.test.ts +881 -604
  119. package/tests/runtime/parser.test.ts +222 -246
  120. package/tests/runtime/registry/DefaultCommandRegistry.test.ts +15 -37
  121. package/tests/runtime/registry/DefaultServiceProviderRegistry.test.ts +2 -8
  122. package/tests/runtime/runner.test.ts +231 -281
  123. package/tests/runtime/scanner.test.ts +277 -475
  124. package/tests/runtime/values/argumentValueMerge.test.ts +133 -81
  125. package/tests/runtime/values/argumentValueValidation.test.ts +444 -588
  126. package/tests/runtime/values/globalCommandValuePopulation.test.ts +71 -253
  127. package/tests/runtime/values/subCommandValuePopulation.test.ts +1342 -1570
  128. package/tests/service/argumentPrompter/ArgumentPrompterServiceProvider.test.ts +3 -12
  129. package/tests/service/argumentPrompter/DefaultArgumentPrompterService.test.ts +36 -45
  130. package/tests/service/asciiBannerGenerator/AsciiBannerGeneratorServiceProvider.test.ts +2 -8
  131. package/tests/service/asciiBannerGenerator/DefaultAsciiBannerGeneratorService.test.ts +40 -62
  132. package/tests/service/banner/BannerServiceProvider.test.ts +5 -18
  133. package/tests/service/banner/command/NoBannerCommand.test.ts +1 -4
  134. package/tests/service/completion/CompletionServiceProvider.test.ts +145 -214
  135. package/tests/service/completion/DefaultCompletionService.test.ts +17 -79
  136. package/tests/service/completion/shell/fish.test.ts +1 -3
  137. package/tests/service/configuration/ConfigurationServiceProvider.test.ts +26 -75
  138. package/tests/service/configuration/DefaultKeyValueService.test.ts +9 -21
  139. package/tests/service/configuration/DefaultSecretService.test.ts +7 -15
  140. package/tests/service/configuration/command/DumpConfigCommand.test.ts +4 -13
  141. package/tests/service/dataDumpGenerator/DataDumpGeneratorServiceProvider.test.ts +6 -12
  142. package/tests/service/dataDumpGenerator/DefaultDataDumpGeneratorService.test.ts +1 -10
  143. package/tests/service/imagePrinter/DefaultImagePrinterService.test.ts +5 -70
  144. package/tests/service/prettyPrinter/DefaultPrettyPrinterService.test.ts +4 -11
  145. package/tests/service/prettyPrinter/PrettyPrinterServiceProvider.test.ts +2 -6
  146. package/tests/service/printer/DefaultPrinterService.test.ts +57 -255
  147. package/tests/service/printer/PrinterServiceProvider.test.ts +2 -8
  148. package/tests/service/printer/command/DarkModeCommand.test.ts +4 -12
  149. package/tests/service/printer/command/LogLevelCommand.test.ts +4 -17
  150. package/tests/service/printer/command/NoColorCommand.test.ts +4 -12
  151. package/tests/service/printer/command/NoHyperlinksCommand.test.ts +7 -21
  152. package/tests/service/printer/terminal/Progress.test.ts +1 -3
  153. package/tests/service/printer/terminal/Spinner.test.ts +2 -8
  154. package/tests/service/prompter/DefaultPrompterService.test.ts +52 -69
  155. package/tests/service/prompter/PrompterServiceProvider.test.ts +2 -8
  156. package/tests/service/shutdown/ShutdownServiceProvider.test.ts +1 -3
  157. package/tests/service/syntaxHighlighter/DefaultSyntaxHighlighterService.test.ts +13 -99
  158. package/tests/service/syntaxHighlighter/SyntaxHighlighterServiceProvider.test.ts +2 -7
  159. package/tests/service/tableGenerator/DefaultTableGeneratorService.test.ts +12 -33
  160. package/tests/service/tableGenerator/TableGeneratorServiceProvider.test.ts +2 -2
  161. package/tests/service/treePrinter/DefaultTreePrinterService.test.ts +4 -6
  162. package/tests/service/treePrinter/TreePrinterServiceProvider.test.ts +4 -8
  163. package/tests/terminal/ImageRenderer.test.ts +2 -11
  164. package/tests/terminal/PngDecoder.test.ts +2 -6
  165. package/tests/util/configHelper.test.ts +55 -137
  166. package/tests/util/envVarHelper.test.ts +46 -110
@@ -1,11 +1,6 @@
1
- import type {
2
- ServiceInfo,
3
- ServiceProvider,
4
- } from "../../api/service/ServiceProvider.ts";
1
+ import type { ServiceInfo, ServiceProvider } from "../../api/service/ServiceProvider.ts";
5
2
  import DefaultPrettyPrinterService from "./DefaultPrettyPrinterService.ts";
6
- import {
7
- PRETTY_PRINTER_SERVICE_ID,
8
- } from "../../api/service/core/PrettyPrinterService.ts";
3
+ import { PRETTY_PRINTER_SERVICE_ID } from "../../api/service/core/PrettyPrinterService.ts";
9
4
  import type Context from "../../api/Context.ts";
10
5
  import type CLIConfig from "../../api/CLIConfig.ts";
11
6
 
@@ -21,9 +16,7 @@ export default class PrettyPrinterServiceProvider implements ServiceProvider {
21
16
  *
22
17
  * @param servicePriority the priority of the service.
23
18
  */
24
- public constructor(
25
- readonly servicePriority: number,
26
- ) {
19
+ public constructor(readonly servicePriority: number) {
27
20
  this.#defaultPrettyPrinterService = new DefaultPrettyPrinterService();
28
21
  }
29
22
 
@@ -27,20 +27,14 @@ export default class DefaultPrinterService implements PrinterService {
27
27
  #spinner: Spinner;
28
28
  #progress: Progress;
29
29
 
30
- async #log(
31
- level: number,
32
- message: string,
33
- icon?: Icon,
34
- ): Promise<void> {
30
+ async #log(level: number, message: string, icon?: Icon): Promise<void> {
35
31
  if (this.#threshold > level) {
36
32
  return;
37
33
  }
38
34
  await this.#spinner.pause();
39
35
  await this.#progress.pause();
40
36
  await this.#stderrTerminal.write(
41
- `${
42
- (icon !== undefined) ? `${this.#iconDefinitions[icon]} ` : ""
43
- }${message}`,
37
+ `${icon !== undefined ? `${this.#iconDefinitions[icon]} ` : ""}${message}`,
44
38
  );
45
39
  this.#spinner.resume();
46
40
  this.#progress.resume();
@@ -65,31 +59,16 @@ export default class DefaultPrinterService implements PrinterService {
65
59
  this.#spinner = new Spinner(this.#stderrTerminal, this.#styler);
66
60
  this.#progress = new Progress(this.#stderrTerminal, this.#styler);
67
61
  this.darkMode = false;
68
- this.#iconDefinitions = [
69
- this.green("✔"),
70
- this.red("✖"),
71
- this.yellow("‼"),
72
- this.blue("ℹ"),
73
- ];
62
+ this.#iconDefinitions = [this.green("✔"), this.red("✖"), this.yellow("‼"), this.blue("ℹ")];
74
63
  }
75
64
 
76
65
  set colorEnabled(enabled: boolean) {
77
66
  this.#styler.colorEnabled = enabled;
78
67
  this.#stdoutIsColor = enabled;
79
68
  if (enabled) {
80
- this.#iconDefinitions = [
81
- this.green("✔"),
82
- this.red("✖"),
83
- this.yellow("‼"),
84
- this.blue("ℹ"),
85
- ];
69
+ this.#iconDefinitions = [this.green("✔"), this.red("✖"), this.yellow("‼"), this.blue("ℹ")];
86
70
  } else {
87
- this.#iconDefinitions = [
88
- "✔",
89
- "✖",
90
- "‼",
91
- "ℹ",
92
- ];
71
+ this.#iconDefinitions = ["✔", "✖", "‼", "ℹ"];
93
72
  }
94
73
  }
95
74
 
@@ -189,66 +168,42 @@ export default class DefaultPrinterService implements PrinterService {
189
168
  }
190
169
 
191
170
  #parseHexColor(hexFormattedColor: string): number {
192
- if (
193
- (hexFormattedColor.length !== 7) ||
194
- (!hexFormattedColor.toLowerCase().startsWith("#"))
195
- ) {
171
+ if (hexFormattedColor.length !== 7 || !hexFormattedColor.toLowerCase().startsWith("#")) {
196
172
  throw new Error(`Invalid color: ${hexFormattedColor}`);
197
173
  }
198
174
  const colorValue = parseInt(hexFormattedColor.slice(1), 16);
199
- if (isNaN(colorValue) || (colorValue < 0 || colorValue > 0xffffff)) {
175
+ if (isNaN(colorValue) || colorValue < 0 || colorValue > 0xffffff) {
200
176
  throw new Error(`Invalid color: ${hexFormattedColor}`);
201
177
  }
202
178
  return colorValue;
203
179
  }
204
180
 
205
181
  public color(message: string, hexFormattedColor: string): string {
206
- return this.#styler.colorText(
207
- message,
208
- this.#parseHexColor(hexFormattedColor),
209
- );
182
+ return this.#styler.colorText(message, this.#parseHexColor(hexFormattedColor));
210
183
  }
211
184
 
212
185
  public backgroundPrimary(message: string): string {
213
- return this.#styler.backgroundColorText(
214
- message,
215
- this.#theme[Color.PRIMARY]!,
216
- );
186
+ return this.#styler.backgroundColorText(message, this.#theme[Color.PRIMARY]!);
217
187
  }
218
188
 
219
189
  public backgroundSecondary(message: string): string {
220
- return this.#styler.backgroundColorText(
221
- message,
222
- this.#theme[Color.SECONDARY]!,
223
- );
190
+ return this.#styler.backgroundColorText(message, this.#theme[Color.SECONDARY]!);
224
191
  }
225
192
 
226
193
  public backgroundEmphasised(message: string): string {
227
- return this.#styler.backgroundColorText(
228
- message,
229
- this.#theme[Color.EMPHASISED]!,
230
- );
194
+ return this.#styler.backgroundColorText(message, this.#theme[Color.EMPHASISED]!);
231
195
  }
232
196
 
233
197
  public backgroundSelected(message: string): string {
234
- return this.#styler.backgroundColorText(
235
- message,
236
- this.#theme[Color.SELECTED]!,
237
- );
198
+ return this.#styler.backgroundColorText(message, this.#theme[Color.SELECTED]!);
238
199
  }
239
200
 
240
201
  public backgroundYellow(message: string): string {
241
- return this.#styler.backgroundColorText(
242
- message,
243
- this.#theme[Color.YELLOW]!,
244
- );
202
+ return this.#styler.backgroundColorText(message, this.#theme[Color.YELLOW]!);
245
203
  }
246
204
 
247
205
  public backgroundOrange(message: string): string {
248
- return this.#styler.backgroundColorText(
249
- message,
250
- this.#theme[Color.ORANGE]!,
251
- );
206
+ return this.#styler.backgroundColorText(message, this.#theme[Color.ORANGE]!);
252
207
  }
253
208
 
254
209
  public backgroundRed(message: string): string {
@@ -256,17 +211,11 @@ export default class DefaultPrinterService implements PrinterService {
256
211
  }
257
212
 
258
213
  public backgroundMagenta(message: string): string {
259
- return this.#styler.backgroundColorText(
260
- message,
261
- this.#theme[Color.MAGENTA]!,
262
- );
214
+ return this.#styler.backgroundColorText(message, this.#theme[Color.MAGENTA]!);
263
215
  }
264
216
 
265
217
  public backgroundViolet(message: string): string {
266
- return this.#styler.backgroundColorText(
267
- message,
268
- this.#theme[Color.VIOLET]!,
269
- );
218
+ return this.#styler.backgroundColorText(message, this.#theme[Color.VIOLET]!);
270
219
  }
271
220
 
272
221
  public backgroundBlue(message: string): string {
@@ -282,10 +231,7 @@ export default class DefaultPrinterService implements PrinterService {
282
231
  }
283
232
 
284
233
  public backgroundColor(message: string, hexFormattedColor: string): string {
285
- return this.#styler.backgroundColorText(
286
- message,
287
- this.#parseHexColor(hexFormattedColor),
288
- );
234
+ return this.#styler.backgroundColorText(message, this.#parseHexColor(hexFormattedColor));
289
235
  }
290
236
 
291
237
  public async debug(message: string, icon?: Icon): Promise<void> {
@@ -311,9 +257,7 @@ export default class DefaultPrinterService implements PrinterService {
311
257
  const colorMessage = this.#stdoutIsColor ? this.primary(message) : message;
312
258
 
313
259
  const encoded = this.#encoder.encode(
314
- `${
315
- (icon !== undefined) ? `${this.#iconDefinitions[icon]} ` : ""
316
- }${colorMessage}`,
260
+ `${icon !== undefined ? `${this.#iconDefinitions[icon]} ` : ""}${colorMessage}`,
317
261
  );
318
262
 
319
263
  await writer.ready;
@@ -336,10 +280,7 @@ export default class DefaultPrinterService implements PrinterService {
336
280
  return this.#threshold;
337
281
  }
338
282
 
339
- public async showSpinner(
340
- message?: string,
341
- style?: SpinnerStyle,
342
- ): Promise<void> {
283
+ public async showSpinner(message?: string, style?: SpinnerStyle): Promise<void> {
343
284
  await this.#progress.hideAll();
344
285
  if (this.#threshold > Level.INFO) {
345
286
  return;
@@ -380,11 +321,7 @@ export default class DefaultPrinterService implements PrinterService {
380
321
  await this.#progress.hideAll();
381
322
  }
382
323
 
383
- public updateProgressBar(
384
- handle: number,
385
- current: number,
386
- message?: string,
387
- ): void {
324
+ public updateProgressBar(handle: number, current: number, message?: string): void {
388
325
  if (this.#threshold > Level.INFO) {
389
326
  return;
390
327
  }
@@ -1,9 +1,6 @@
1
1
  import type Context from "../../api/Context.ts";
2
2
  import LogLevelCommand from "./command/LogLevelCommand.ts";
3
- import type {
4
- ServiceInfo,
5
- ServiceProvider,
6
- } from "../../api/service/ServiceProvider.ts";
3
+ import type { ServiceInfo, ServiceProvider } from "../../api/service/ServiceProvider.ts";
7
4
  import type PrinterService from "../../api/service/core/PrinterService.ts";
8
5
  import { PRINTER_SERVICE_ID } from "../../api/service/core/PrinterService.ts";
9
6
  import DarkModeCommand from "./command/DarkModeCommand.ts";
@@ -27,10 +24,7 @@ export default class PrinterServiceProvider implements ServiceProvider {
27
24
  * @param servicePriority the priority of the service.
28
25
  * @param printerService the PrinterService implementation to use.
29
26
  */
30
- public constructor(
31
- servicePriority: number,
32
- printerService: PrinterService,
33
- ) {
27
+ public constructor(servicePriority: number, printerService: PrinterService) {
34
28
  this.servicePriority = servicePriority;
35
29
  this.printerService = printerService;
36
30
  }
@@ -48,9 +42,7 @@ export default class PrinterServiceProvider implements ServiceProvider {
48
42
  }
49
43
 
50
44
  initService(context: Context): Promise<void> {
51
- const shutdownService = context.getServiceById(
52
- SHUTDOWN_SERVICE_ID,
53
- ) as ShutdownService;
45
+ const shutdownService = context.getServiceById(SHUTDOWN_SERVICE_ID) as ShutdownService;
54
46
  shutdownService.addShutdownListener(async () => {
55
47
  await this.printerService.hideSpinner();
56
48
  await this.printerService.hideAllProgressBars();
@@ -23,20 +23,13 @@ export default class DarkModeCommand implements GlobalModifierCommand {
23
23
 
24
24
  readonly #printerServiceProvider: PrinterServiceProvider;
25
25
 
26
- public constructor(
27
- printerServiceProvider: PrinterServiceProvider,
28
- executePriority: number,
29
- ) {
26
+ public constructor(printerServiceProvider: PrinterServiceProvider, executePriority: number) {
30
27
  this.#printerServiceProvider = printerServiceProvider;
31
28
  this.executePriority = executePriority;
32
29
  }
33
30
 
34
- public execute(
35
- _context: Context,
36
- argumentValue: ArgumentSingleValueType,
37
- ): Promise<void> {
38
- this.#printerServiceProvider.printerService!.darkMode =
39
- argumentValue as boolean;
31
+ public execute(_context: Context, argumentValue: ArgumentSingleValueType): Promise<void> {
32
+ this.#printerServiceProvider.printerService!.darkMode = argumentValue as boolean;
40
33
 
41
34
  return Promise.resolve();
42
35
  }
@@ -17,12 +17,7 @@ export default class LogLevelCommand implements GlobalModifierCommand {
17
17
  readonly enableConfiguration = true;
18
18
  readonly argument: GlobalCommandArgument = {
19
19
  type: ArgumentValueTypeName.STRING,
20
- allowableValues: [
21
- "DEBUG",
22
- "INFO",
23
- "WARN",
24
- "ERROR",
25
- ],
20
+ allowableValues: ["DEBUG", "INFO", "WARN", "ERROR"],
26
21
  isCaseInsensitive: true,
27
22
  defaultValue: "INFO",
28
23
  configurationKey: "LOG_LEVEL",
@@ -31,40 +26,26 @@ export default class LogLevelCommand implements GlobalModifierCommand {
31
26
 
32
27
  readonly #printerServiceProvider: PrinterServiceProvider;
33
28
 
34
- public constructor(
35
- printerServiceProvider: PrinterServiceProvider,
36
- executePriority: number,
37
- ) {
29
+ public constructor(printerServiceProvider: PrinterServiceProvider, executePriority: number) {
38
30
  this.#printerServiceProvider = printerServiceProvider;
39
31
  this.executePriority = executePriority;
40
32
  }
41
33
 
42
- public execute(
43
- _context: Context,
44
- argumentValue: ArgumentSingleValueType,
45
- ): Promise<void> {
34
+ public execute(_context: Context, argumentValue: ArgumentSingleValueType): Promise<void> {
46
35
  const logLevel = argumentValue as string;
47
36
 
48
37
  switch (logLevel.toUpperCase()) {
49
38
  case "DEBUG":
50
- this.#printerServiceProvider.printerService!.setLevel(
51
- Level.DEBUG,
52
- );
39
+ this.#printerServiceProvider.printerService!.setLevel(Level.DEBUG);
53
40
  break;
54
41
  case "INFO":
55
- this.#printerServiceProvider.printerService!.setLevel(
56
- Level.INFO,
57
- );
42
+ this.#printerServiceProvider.printerService!.setLevel(Level.INFO);
58
43
  break;
59
44
  case "WARN":
60
- this.#printerServiceProvider.printerService!.setLevel(
61
- Level.WARN,
62
- );
45
+ this.#printerServiceProvider.printerService!.setLevel(Level.WARN);
63
46
  break;
64
47
  case "ERROR":
65
- this.#printerServiceProvider.printerService!.setLevel(
66
- Level.ERROR,
67
- );
48
+ this.#printerServiceProvider.printerService!.setLevel(Level.ERROR);
68
49
  break;
69
50
  }
70
51
 
@@ -23,20 +23,13 @@ export default class NoColorCommand implements GlobalModifierCommand {
23
23
 
24
24
  readonly #printerServiceProvider: PrinterServiceProvider;
25
25
 
26
- public constructor(
27
- printerServiceProvider: PrinterServiceProvider,
28
- executePriority: number,
29
- ) {
26
+ public constructor(printerServiceProvider: PrinterServiceProvider, executePriority: number) {
30
27
  this.#printerServiceProvider = printerServiceProvider;
31
28
  this.executePriority = executePriority;
32
29
  }
33
30
 
34
- public execute(
35
- _context: Context,
36
- argumentValue: ArgumentSingleValueType,
37
- ): Promise<void> {
38
- this.#printerServiceProvider.printerService!.colorEnabled =
39
- !argumentValue as boolean;
31
+ public execute(_context: Context, argumentValue: ArgumentSingleValueType): Promise<void> {
32
+ this.#printerServiceProvider.printerService!.colorEnabled = !argumentValue as boolean;
40
33
 
41
34
  return Promise.resolve();
42
35
  }
@@ -20,20 +20,13 @@ export default class NoHyperlinksCommand implements GlobalModifierCommand {
20
20
 
21
21
  readonly #printerServiceProvider: PrinterServiceProvider;
22
22
 
23
- public constructor(
24
- printerServiceProvider: PrinterServiceProvider,
25
- executePriority: number,
26
- ) {
23
+ public constructor(printerServiceProvider: PrinterServiceProvider, executePriority: number) {
27
24
  this.#printerServiceProvider = printerServiceProvider;
28
25
  this.executePriority = executePriority;
29
26
  }
30
27
 
31
- public execute(
32
- _context: Context,
33
- argumentValue: ArgumentSingleValueType,
34
- ): Promise<void> {
35
- this.#printerServiceProvider.printerService!.hyperlinksEnabled =
36
- !argumentValue as boolean;
28
+ public execute(_context: Context, argumentValue: ArgumentSingleValueType): Promise<void> {
29
+ this.#printerServiceProvider.printerService!.hyperlinksEnabled = !argumentValue as boolean;
37
30
 
38
31
  return Promise.resolve();
39
32
  }
@@ -6,10 +6,7 @@ const RATE_SMOOTHING_FACTOR = 0.005;
6
6
  export { ProgressStyle } from "../../../api/service/core/PrinterService.ts";
7
7
  import { ProgressStyle } from "../../../api/service/core/PrinterService.ts";
8
8
 
9
- const STYLE_CHARS: Record<
10
- ProgressStyle,
11
- { complete: string; remaining: string }
12
- > = {
9
+ const STYLE_CHARS: Record<ProgressStyle, { complete: string; remaining: string }> = {
13
10
  [ProgressStyle.STROKE]: { complete: "=", remaining: "-" },
14
11
  [ProgressStyle.FILL]: { complete: "▰", remaining: "▱" },
15
12
  };
@@ -44,12 +41,7 @@ export default class Progress {
44
41
  this.#styler = styler;
45
42
  }
46
43
 
47
- public add(
48
- units: string,
49
- message: string,
50
- total: number,
51
- current: number,
52
- ): number {
44
+ public add(units: string, message: string, total: number, current: number): number {
53
45
  if (total < 0) {
54
46
  total = 100;
55
47
  }
@@ -86,13 +78,11 @@ export default class Progress {
86
78
  if (bar.lastMillis === undefined) {
87
79
  bar.rate = ((current - bar.current) * 1000) / (now - bar.startMillis!);
88
80
  } else {
89
- let currentRate = ((current - bar.current) * 1000) /
90
- (now - bar.lastMillis!);
81
+ let currentRate = ((current - bar.current) * 1000) / (now - bar.lastMillis!);
91
82
  if (!isFinite(currentRate)) {
92
83
  currentRate = 0;
93
84
  }
94
- bar.rate = (currentRate * RATE_SMOOTHING_FACTOR) +
95
- (bar.rate! * (1 - RATE_SMOOTHING_FACTOR));
85
+ bar.rate = currentRate * RATE_SMOOTHING_FACTOR + bar.rate! * (1 - RATE_SMOOTHING_FACTOR);
96
86
  }
97
87
  bar.lastMillis = now;
98
88
  }
@@ -108,7 +98,7 @@ export default class Progress {
108
98
  if (current > bar.total) {
109
99
  current = bar.total;
110
100
  }
111
- if ((current === bar.total) && (bar.endMillis === undefined)) {
101
+ if (current === bar.total && bar.endMillis === undefined) {
112
102
  bar.endMillis = Date.now();
113
103
  }
114
104
 
@@ -189,7 +179,7 @@ export default class Progress {
189
179
  const now = Date.now();
190
180
 
191
181
  // force render after one second to update newly calculated eta
192
- if ((now - this.#lastRenderTime >= 1000) && !this.#isDirty) {
182
+ if (now - this.#lastRenderTime >= 1000 && !this.#isDirty) {
193
183
  this.#bars.forEach((bar) => this.#updateRate(bar, bar.current));
194
184
  this.#isDirty = true;
195
185
  }
@@ -204,69 +194,80 @@ export default class Progress {
204
194
  const consoleWidth = this.#terminal.columns();
205
195
  const lines: Array<string> = [];
206
196
 
207
- const barInfo: Array<
208
- {
209
- name: string;
210
- prefix: string;
211
- available: number;
212
- suffix: string;
213
- bar: Bar;
214
- }
215
- > = [];
197
+ const barInfo: Array<{
198
+ name: string;
199
+ prefix: string;
200
+ available: number;
201
+ suffix: string;
202
+ bar: Bar;
203
+ }> = [];
216
204
 
217
205
  this.#bars.forEach((bar) => {
218
- const name = `${this.#styler.colorText(bar.name, this.#valColor)}${
219
- this.#styler.colorText(":", this.#labColor)
220
- }`;
206
+ const name = `${this.#styler.colorText(bar.name, this.#valColor)}${this.#styler.colorText(
207
+ ":",
208
+ this.#labColor,
209
+ )}`;
221
210
  const prefix = `${this.#styler.colorText("[", this.#labColor)}`;
222
211
  let visibleWidth = 1;
223
212
  const percentString = ((bar.current / bar.total) * 100).toFixed(2);
224
- const percent = this.#styler.colorText(
225
- percentString,
226
- this.#valColor,
227
- ) + this.#styler.colorText("%,", this.#labColor);
213
+ const percent =
214
+ this.#styler.colorText(percentString, this.#valColor) +
215
+ this.#styler.colorText("%,", this.#labColor);
228
216
  visibleWidth += percentString.length + 1;
229
217
 
230
- const rate = `${
231
- this.#styler.colorText(
232
- (bar.rate === undefined) ? "-" : bar.rate.toFixed(2) + "",
233
- this.#valColor,
234
- )
235
- }`;
218
+ const rateText = bar.rate === undefined ? "-" : bar.rate.toFixed(2) + "";
219
+ const rate = `${this.#styler.colorText(rateText, this.#valColor)}`;
236
220
 
237
221
  let suffix = `${this.#styler.colorText("]", this.#labColor)} ${percent} `;
238
222
  visibleWidth += 3;
239
223
  if (bar.current === bar.total) {
240
224
  const taken = this.#formatTime(bar.endMillis! - bar.startMillis!);
241
225
  const totalString = bar.total + "";
242
- suffix += `${this.#styler.colorText(totalString, this.#valColor)}${
243
- this.#styler.colorText(bar.units + ", rate:", this.#labColor)
244
- } ${rate}${
245
- this.#styler.colorText(
246
- bar.units + "/s, time taken:",
247
- this.#labColor,
248
- )
249
- } ${taken}`;
250
- visibleWidth + totalString.length + bar.units.length + 7 + 1 +
251
- rate.length + bar.units.length + 15 + 1 + taken.length;
226
+ suffix += `${this.#styler.colorText(totalString, this.#valColor)}${this.#styler.colorText(
227
+ bar.units + ", rate:",
228
+ this.#labColor,
229
+ )} ${rate}${this.#styler.colorText(
230
+ bar.units + "/s, time taken:",
231
+ this.#labColor,
232
+ )} ${taken}`;
233
+ visibleWidth +=
234
+ totalString.length +
235
+ bar.units.length +
236
+ 7 +
237
+ 1 +
238
+ rateText.length +
239
+ bar.units.length +
240
+ 15 +
241
+ 1 +
242
+ taken.length;
252
243
  } else {
253
- const remaining = ((bar.rate === undefined) || (bar.rate === 0))
254
- ? "-"
255
- : this.#formatTime(((bar.total - bar.current) / bar.rate) * 1000);
244
+ const remaining =
245
+ bar.rate === undefined || bar.rate === 0
246
+ ? "-"
247
+ : this.#formatTime(((bar.total - bar.current) / bar.rate) * 1000);
256
248
  const currentString = bar.current + "";
257
249
  const totalString = bar.total + "";
258
- suffix += `${this.#styler.colorText(currentString, this.#valColor)}${
259
- this.#styler.colorText("/", this.#labColor)
260
- }${this.#styler.colorText(totalString, this.#valColor)}${
261
- this.#styler.colorText(bar.units + ", rate:", this.#labColor)
262
- } ${rate}${
263
- this.#styler.colorText(
264
- bar.units + "/s, time remaining:",
265
- this.#labColor,
266
- )
267
- } ${remaining}`;
268
- visibleWidth + currentString.length + 1 + totalString.length +
269
- bar.units.length + 7 + 1 + rate.length + bar.units.length + 19 + 1 +
250
+ suffix += `${this.#styler.colorText(currentString, this.#valColor)}${this.#styler.colorText(
251
+ "/",
252
+ this.#labColor,
253
+ )}${this.#styler.colorText(totalString, this.#valColor)}${this.#styler.colorText(
254
+ bar.units + ", rate:",
255
+ this.#labColor,
256
+ )} ${rate}${this.#styler.colorText(
257
+ bar.units + "/s, time remaining:",
258
+ this.#labColor,
259
+ )} ${remaining}`;
260
+ visibleWidth +=
261
+ currentString.length +
262
+ 1 +
263
+ totalString.length +
264
+ bar.units.length +
265
+ 7 +
266
+ 1 +
267
+ rateText.length +
268
+ bar.units.length +
269
+ 19 +
270
+ 1 +
270
271
  remaining.length;
271
272
  }
272
273
  let available = consoleWidth - visibleWidth;
@@ -291,9 +292,7 @@ export default class Progress {
291
292
  totalLength = Math.min(50, totalLength);
292
293
 
293
294
  barInfo.forEach((barInfo) => {
294
- const completeLength = Math.floor(
295
- totalLength * barInfo.bar.current / barInfo.bar.total,
296
- );
295
+ const completeLength = Math.floor((totalLength * barInfo.bar.current) / barInfo.bar.total);
297
296
  const chars = STYLE_CHARS[this.#style];
298
297
  const complete = this.#styler.colorText(
299
298
  chars.complete.repeat(completeLength),
@@ -351,40 +350,50 @@ export default class Progress {
351
350
  #formatTime(millis: number): string {
352
351
  let sec = millis / 1000;
353
352
  if (sec < 60) {
354
- return `${this.#styler.colorText(sec.toFixed(0), this.#valColor)}${
355
- this.#styler.colorText("s", this.#labColor)
356
- }`;
353
+ return `${this.#styler.colorText(sec.toFixed(0), this.#valColor)}${this.#styler.colorText(
354
+ "s",
355
+ this.#labColor,
356
+ )}`;
357
357
  }
358
358
  let min = Math.floor(sec / 60);
359
359
  sec %= 60;
360
360
  if (min < 60) {
361
- return `${this.#styler.colorText(min.toFixed(0), this.#valColor)}${
362
- this.#styler.colorText("m", this.#labColor)
363
- } ${this.#styler.colorText(sec.toFixed(0), this.#valColor)}${
364
- this.#styler.colorText("s", this.#labColor)
365
- }`;
361
+ return `${this.#styler.colorText(min.toFixed(0), this.#valColor)}${this.#styler.colorText(
362
+ "m",
363
+ this.#labColor,
364
+ )} ${this.#styler.colorText(sec.toFixed(0), this.#valColor)}${this.#styler.colorText(
365
+ "s",
366
+ this.#labColor,
367
+ )}`;
366
368
  }
367
369
  let hour = Math.floor(min / 60);
368
370
  min %= 60;
369
371
  if (hour < 24) {
370
- return `${this.#styler.colorText(hour.toFixed(0), this.#valColor)}${
371
- this.#styler.colorText("h", this.#labColor)
372
- } ${this.#styler.colorText(min.toFixed(0), this.#valColor)}${
373
- this.#styler.colorText("m", this.#labColor)
374
- } ${this.#styler.colorText(sec.toFixed(0), this.#valColor)}${
375
- this.#styler.colorText("s", this.#labColor)
376
- }`;
372
+ return `${this.#styler.colorText(hour.toFixed(0), this.#valColor)}${this.#styler.colorText(
373
+ "h",
374
+ this.#labColor,
375
+ )} ${this.#styler.colorText(min.toFixed(0), this.#valColor)}${this.#styler.colorText(
376
+ "m",
377
+ this.#labColor,
378
+ )} ${this.#styler.colorText(sec.toFixed(0), this.#valColor)}${this.#styler.colorText(
379
+ "s",
380
+ this.#labColor,
381
+ )}`;
377
382
  }
378
383
  const day = Math.floor(hour / 24);
379
384
  hour %= 24;
380
- return `${this.#styler.colorText(day.toFixed(0), this.#valColor)}${
381
- this.#styler.colorText("d", this.#labColor)
382
- } ${this.#styler.colorText(hour.toFixed(0), this.#valColor)}${
383
- this.#styler.colorText("h", this.#labColor)
384
- } ${this.#styler.colorText(min.toFixed(0), this.#valColor)}${
385
- this.#styler.colorText("m", this.#labColor)
386
- } ${this.#styler.colorText(sec.toFixed(0), this.#valColor)}${
387
- this.#styler.colorText("s", this.#labColor)
388
- }`;
385
+ return `${this.#styler.colorText(day.toFixed(0), this.#valColor)}${this.#styler.colorText(
386
+ "d",
387
+ this.#labColor,
388
+ )} ${this.#styler.colorText(hour.toFixed(0), this.#valColor)}${this.#styler.colorText(
389
+ "h",
390
+ this.#labColor,
391
+ )} ${this.#styler.colorText(min.toFixed(0), this.#valColor)}${this.#styler.colorText(
392
+ "m",
393
+ this.#labColor,
394
+ )} ${this.#styler.colorText(sec.toFixed(0), this.#valColor)}${this.#styler.colorText(
395
+ "s",
396
+ this.#labColor,
397
+ )}`;
389
398
  }
390
399
  }