@flowscripter/dynamic-cli-framework-api 1.0.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 (174) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +59 -0
  3. package/dist/index.d.ts +74 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +29 -0
  6. package/dist/src/BaseCLIFeatureOptions.d.ts +12 -0
  7. package/dist/src/BaseCLIFeatureOptions.d.ts.map +1 -0
  8. package/dist/src/BaseCLIFeatureOptions.js +0 -0
  9. package/dist/src/CLI.d.ts +17 -0
  10. package/dist/src/CLI.d.ts.map +1 -0
  11. package/dist/src/CLI.js +0 -0
  12. package/dist/src/CLIConfig.d.ts +22 -0
  13. package/dist/src/CLIConfig.d.ts.map +1 -0
  14. package/dist/src/CLIConfig.js +0 -0
  15. package/dist/src/Context.d.ts +23 -0
  16. package/dist/src/Context.d.ts.map +1 -0
  17. package/dist/src/Context.js +0 -0
  18. package/dist/src/ParseResult.d.ts +33 -0
  19. package/dist/src/ParseResult.d.ts.map +1 -0
  20. package/dist/src/ParseResult.js +0 -0
  21. package/dist/src/RunResult.d.ts +128 -0
  22. package/dist/src/RunResult.d.ts.map +1 -0
  23. package/dist/src/RunResult.js +73 -0
  24. package/dist/src/argument/Argument.d.ts +62 -0
  25. package/dist/src/argument/Argument.d.ts.map +1 -0
  26. package/dist/src/argument/Argument.js +0 -0
  27. package/dist/src/argument/ArgumentValueTypes.d.ts +68 -0
  28. package/dist/src/argument/ArgumentValueTypes.d.ts.map +1 -0
  29. package/dist/src/argument/ArgumentValueTypes.js +18 -0
  30. package/dist/src/argument/ComplexOption.d.ts +21 -0
  31. package/dist/src/argument/ComplexOption.d.ts.map +1 -0
  32. package/dist/src/argument/ComplexOption.js +1 -0
  33. package/dist/src/argument/GlobalCommandArgument.d.ts +16 -0
  34. package/dist/src/argument/GlobalCommandArgument.d.ts.map +1 -0
  35. package/dist/src/argument/GlobalCommandArgument.js +0 -0
  36. package/dist/src/argument/Option.d.ts +29 -0
  37. package/dist/src/argument/Option.d.ts.map +1 -0
  38. package/dist/src/argument/Option.js +0 -0
  39. package/dist/src/argument/Positional.d.ts +26 -0
  40. package/dist/src/argument/Positional.d.ts.map +1 -0
  41. package/dist/src/argument/Positional.js +0 -0
  42. package/dist/src/argument/SubCommandArgument.d.ts +18 -0
  43. package/dist/src/argument/SubCommandArgument.d.ts.map +1 -0
  44. package/dist/src/argument/SubCommandArgument.js +1 -0
  45. package/dist/src/command/Command.d.ts +26 -0
  46. package/dist/src/command/Command.d.ts.map +1 -0
  47. package/dist/src/command/Command.js +0 -0
  48. package/dist/src/command/GlobalCommand.d.ts +28 -0
  49. package/dist/src/command/GlobalCommand.d.ts.map +1 -0
  50. package/dist/src/command/GlobalCommand.js +0 -0
  51. package/dist/src/command/GlobalModifierCommand.d.ts +12 -0
  52. package/dist/src/command/GlobalModifierCommand.d.ts.map +1 -0
  53. package/dist/src/command/GlobalModifierCommand.js +0 -0
  54. package/dist/src/command/GroupCommand.d.ts +19 -0
  55. package/dist/src/command/GroupCommand.d.ts.map +1 -0
  56. package/dist/src/command/GroupCommand.js +0 -0
  57. package/dist/src/command/SubCommand.d.ts +37 -0
  58. package/dist/src/command/SubCommand.d.ts.map +1 -0
  59. package/dist/src/command/SubCommand.js +0 -0
  60. package/dist/src/command/UsageExample.d.ts +20 -0
  61. package/dist/src/command/UsageExample.d.ts.map +1 -0
  62. package/dist/src/command/UsageExample.js +0 -0
  63. package/dist/src/plugin/CLIPlugin.d.ts +32 -0
  64. package/dist/src/plugin/CLIPlugin.d.ts.map +1 -0
  65. package/dist/src/plugin/CLIPlugin.js +2 -0
  66. package/dist/src/plugin/CommandFactory.d.ts +23 -0
  67. package/dist/src/plugin/CommandFactory.d.ts.map +1 -0
  68. package/dist/src/plugin/CommandFactory.js +7 -0
  69. package/dist/src/plugin/ServiceProviderFactory.d.ts +25 -0
  70. package/dist/src/plugin/ServiceProviderFactory.d.ts.map +1 -0
  71. package/dist/src/plugin/ServiceProviderFactory.js +7 -0
  72. package/dist/src/plugin/createCLIPlugin.d.ts +14 -0
  73. package/dist/src/plugin/createCLIPlugin.d.ts.map +1 -0
  74. package/dist/src/plugin/createCLIPlugin.js +30 -0
  75. package/dist/src/registry/CommandRegistry.d.ts +89 -0
  76. package/dist/src/registry/CommandRegistry.d.ts.map +1 -0
  77. package/dist/src/registry/CommandRegistry.js +0 -0
  78. package/dist/src/registry/ServiceProviderRegistry.d.ts +11 -0
  79. package/dist/src/registry/ServiceProviderRegistry.d.ts.map +1 -0
  80. package/dist/src/registry/ServiceProviderRegistry.js +0 -0
  81. package/dist/src/service/ServiceProvider.d.ts +47 -0
  82. package/dist/src/service/ServiceProvider.d.ts.map +1 -0
  83. package/dist/src/service/ServiceProvider.js +0 -0
  84. package/dist/src/service/core/ArgumentPrompterService.d.ts +6 -0
  85. package/dist/src/service/core/ArgumentPrompterService.d.ts.map +1 -0
  86. package/dist/src/service/core/ArgumentPrompterService.js +1 -0
  87. package/dist/src/service/core/AsciiBannerGeneratorService.d.ts +59 -0
  88. package/dist/src/service/core/AsciiBannerGeneratorService.d.ts.map +1 -0
  89. package/dist/src/service/core/AsciiBannerGeneratorService.js +1 -0
  90. package/dist/src/service/core/CompletionService.d.ts +22 -0
  91. package/dist/src/service/core/CompletionService.d.ts.map +1 -0
  92. package/dist/src/service/core/CompletionService.js +8 -0
  93. package/dist/src/service/core/DataDumpGeneratorService.d.ts +22 -0
  94. package/dist/src/service/core/DataDumpGeneratorService.d.ts.map +1 -0
  95. package/dist/src/service/core/DataDumpGeneratorService.js +7 -0
  96. package/dist/src/service/core/ImagePrinterService.d.ts +21 -0
  97. package/dist/src/service/core/ImagePrinterService.d.ts.map +1 -0
  98. package/dist/src/service/core/ImagePrinterService.js +1 -0
  99. package/dist/src/service/core/KeyValueService.d.ts +40 -0
  100. package/dist/src/service/core/KeyValueService.d.ts.map +1 -0
  101. package/dist/src/service/core/KeyValueService.js +7 -0
  102. package/dist/src/service/core/PluginService.d.ts +56 -0
  103. package/dist/src/service/core/PluginService.d.ts.map +1 -0
  104. package/dist/src/service/core/PluginService.js +6 -0
  105. package/dist/src/service/core/PrettyPrinterService.d.ts +35 -0
  106. package/dist/src/service/core/PrettyPrinterService.d.ts.map +1 -0
  107. package/dist/src/service/core/PrettyPrinterService.js +1 -0
  108. package/dist/src/service/core/PrinterService.d.ts +380 -0
  109. package/dist/src/service/core/PrinterService.d.ts.map +1 -0
  110. package/dist/src/service/core/PrinterService.js +42 -0
  111. package/dist/src/service/core/PrompterService.d.ts +35 -0
  112. package/dist/src/service/core/PrompterService.d.ts.map +1 -0
  113. package/dist/src/service/core/PrompterService.js +10 -0
  114. package/dist/src/service/core/SecretService.d.ts +25 -0
  115. package/dist/src/service/core/SecretService.d.ts.map +1 -0
  116. package/dist/src/service/core/SecretService.js +0 -0
  117. package/dist/src/service/core/ShutdownService.d.ts +24 -0
  118. package/dist/src/service/core/ShutdownService.d.ts.map +1 -0
  119. package/dist/src/service/core/ShutdownService.js +1 -0
  120. package/dist/src/service/core/SyntaxHighlighterService.d.ts +49 -0
  121. package/dist/src/service/core/SyntaxHighlighterService.d.ts.map +1 -0
  122. package/dist/src/service/core/SyntaxHighlighterService.js +1 -0
  123. package/dist/src/service/core/Table.d.ts +18 -0
  124. package/dist/src/service/core/Table.d.ts.map +1 -0
  125. package/dist/src/service/core/Table.js +49 -0
  126. package/dist/src/service/core/TableGeneratorService.d.ts +32 -0
  127. package/dist/src/service/core/TableGeneratorService.d.ts.map +1 -0
  128. package/dist/src/service/core/TableGeneratorService.js +7 -0
  129. package/dist/src/service/core/TreePrinterService.d.ts +9 -0
  130. package/dist/src/service/core/TreePrinterService.d.ts.map +1 -0
  131. package/dist/src/service/core/TreePrinterService.js +1 -0
  132. package/index.ts +138 -0
  133. package/package.json +66 -0
  134. package/src/CLI.ts +17 -0
  135. package/src/CLIConfig.ts +24 -0
  136. package/src/Context.ts +25 -0
  137. package/src/ParseResult.ts +40 -0
  138. package/src/RunResult.ts +158 -0
  139. package/src/argument/Argument.ts +75 -0
  140. package/src/argument/ArgumentValueTypes.ts +80 -0
  141. package/src/argument/ComplexOption.ts +27 -0
  142. package/src/argument/GlobalCommandArgument.ts +17 -0
  143. package/src/argument/Option.ts +32 -0
  144. package/src/argument/Positional.ts +27 -0
  145. package/src/argument/SubCommandArgument.ts +20 -0
  146. package/src/command/Command.ts +28 -0
  147. package/src/command/GlobalCommand.ts +30 -0
  148. package/src/command/GlobalModifierCommand.ts +12 -0
  149. package/src/command/GroupCommand.ts +20 -0
  150. package/src/command/SubCommand.ts +41 -0
  151. package/src/command/UsageExample.ts +21 -0
  152. package/src/plugin/CLIPlugin.ts +36 -0
  153. package/src/plugin/CommandFactory.ts +25 -0
  154. package/src/plugin/ServiceProviderFactory.ts +27 -0
  155. package/src/plugin/createCLIPlugin.ts +47 -0
  156. package/src/registry/CommandRegistry.ts +116 -0
  157. package/src/registry/ServiceProviderRegistry.ts +11 -0
  158. package/src/service/ServiceProvider.ts +52 -0
  159. package/src/service/core/ArgumentPrompterService.ts +8 -0
  160. package/src/service/core/AsciiBannerGeneratorService.ts +69 -0
  161. package/src/service/core/CompletionService.ts +32 -0
  162. package/src/service/core/DataDumpGeneratorService.ts +27 -0
  163. package/src/service/core/ImagePrinterService.ts +25 -0
  164. package/src/service/core/KeyValueService.ts +44 -0
  165. package/src/service/core/PluginService.ts +64 -0
  166. package/src/service/core/PrettyPrinterService.ts +39 -0
  167. package/src/service/core/PrinterService.ts +446 -0
  168. package/src/service/core/PrompterService.ts +42 -0
  169. package/src/service/core/SecretService.ts +27 -0
  170. package/src/service/core/ShutdownService.ts +27 -0
  171. package/src/service/core/SyntaxHighlighterService.ts +54 -0
  172. package/src/service/core/Table.ts +67 -0
  173. package/src/service/core/TableGeneratorService.ts +39 -0
  174. package/src/service/core/TreePrinterService.ts +10 -0
@@ -0,0 +1,446 @@
1
+ export const PRINTER_SERVICE_ID = "@flowscripter/dynamic-cli-framework/printer-service";
2
+ import { WritableStream } from "node:stream/web";
3
+
4
+ /**
5
+ * Enum of message importance level.
6
+ */
7
+ export enum Level {
8
+ DEBUG = 0,
9
+ INFO = 1,
10
+ WARN = 2,
11
+ ERROR = 3,
12
+ }
13
+
14
+ /**
15
+ * Enum of spinner animation styles.
16
+ */
17
+ export enum SpinnerStyle {
18
+ BOX = "BOX",
19
+ STAR = "STAR",
20
+ }
21
+
22
+ /**
23
+ * Enum of progress bar rendering styles.
24
+ */
25
+ export enum ProgressStyle {
26
+ STROKE = "STROKE",
27
+ FILL = "FILL",
28
+ }
29
+
30
+ /**
31
+ * Enum of message icons.
32
+ */
33
+ export enum Icon {
34
+ // Will be displayed in green if {@link Printer.colorEnabled} is `true`.
35
+ SUCCESS = 0,
36
+ // Will be displayed in red if {@link Printer.colorEnabled} is `true`.
37
+ FAILURE = 1,
38
+ // Will be displayed in yellow if {@link Printer.colorEnabled} is `true`.
39
+ ALERT = 2,
40
+ // Will be displayed in blue if {@link Printer.colorEnabled} is `true`.
41
+ INFORMATION = 3,
42
+ }
43
+
44
+ /**
45
+ * Service allowing a {@link Command} to output user messages to `stdout` and/or `stderr`.
46
+ *
47
+ * Output to `stdout` is via {@link print} whilst output to `stderr` is via a filtered logging mechanism
48
+ * using {@link debug}, {@link info}, {@link warn} and {@link error}.
49
+ */
50
+ export default interface PrinterService {
51
+ /**
52
+ * Disable or enable color output for messages.
53
+ */
54
+ colorEnabled: boolean;
55
+
56
+ /**
57
+ * Disable or enable hyperlink output for messages.
58
+ */
59
+ hyperlinksEnabled: boolean;
60
+
61
+ /**
62
+ * Enable or disable dark mode. Default is disabled i.e. `false`.
63
+ */
64
+ darkMode: boolean;
65
+
66
+ /**
67
+ * The WritableStream used for `stdout`. Can be accessed directly for output of binary data etc.
68
+ */
69
+ stdoutWritable: WritableStream;
70
+
71
+ /**
72
+ * The WritableStream used for `stderr`. Can be accessed directly for output of binary data etc.
73
+ */
74
+ stderrWritable: WritableStream;
75
+
76
+ /**
77
+ * Return the provided message so that the foreground is colored as primary content. This is the default
78
+ * calor applied. The actual color will depend on the value of {@link darkMode}.
79
+ * Has no effect if {@link colorEnabled} is `false`.
80
+ */
81
+ primary(message: string): string;
82
+
83
+ /**
84
+ * Return the provided message so that the foreground is colored as secondary content.
85
+ * The actual color will depend on the value of {@link darkMode}.
86
+ * Has no effect if {@link colorEnabled} is `false`.
87
+ */
88
+ secondary(message: string): string;
89
+
90
+ /**
91
+ * Return the provided message so that the foreground is colored as emphasised content.
92
+ * The actual color will depend on the value of {@link darkMode}.
93
+ * Has no effect if {@link colorEnabled} is `false`.
94
+ */
95
+ emphasised(message: string): string;
96
+
97
+ /**
98
+ * Return the provided message so that the background is colored as selected content.
99
+ * The actual color will depend on the value of {@link darkMode}.
100
+ * Has no effect if {@link colorEnabled} is `false`.
101
+ */
102
+ selected(message: string): string;
103
+
104
+ /**
105
+ * Return the provided message so that the text is displayed in italic.
106
+ */
107
+ italic(message: string): string;
108
+
109
+ /**
110
+ * Return the provided message so that the foreground is yellow.
111
+ * Has no effect if {@link colorEnabled} is `false`.
112
+ */
113
+ yellow(message: string): string;
114
+
115
+ /**
116
+ * Return the provided message so that the foreground is orange.
117
+ * Has no effect if {@link colorEnabled} is `false`.
118
+ */
119
+ orange(message: string): string;
120
+
121
+ /**
122
+ * Return the provided message so that the foreground is red.
123
+ * Has no effect if {@link colorEnabled} is `false`.
124
+ */
125
+ red(message: string): string;
126
+
127
+ /**
128
+ * Return the provided message so that the foreground is magenta.
129
+ * Has no effect if {@link colorEnabled} is `false`.
130
+ */
131
+ magenta(message: string): string;
132
+
133
+ /**
134
+ * Return the provided message so that the foreground is violet.
135
+ * Has no effect if {@link colorEnabled} is `false`.
136
+ */
137
+ violet(message: string): string;
138
+
139
+ /**
140
+ * Return the provided message so that the foreground is blue.
141
+ * Has no effect if {@link colorEnabled} is `false`.
142
+ */
143
+ blue(message: string): string;
144
+
145
+ /**
146
+ * Return the provided message so that the foreground is cyan.
147
+ * Has no effect if {@link colorEnabled} is `false`.
148
+ */
149
+ cyan(message: string): string;
150
+
151
+ /**
152
+ * Return the provided message so that the foreground is green.
153
+ * Has no effect if {@link colorEnabled} is `false`.
154
+ */
155
+ green(message: string): string;
156
+
157
+ /**
158
+ * Return the provided message so that the foreground is the specified color.
159
+ * Has no effect if {@link colorEnabled} is `false`.
160
+ *
161
+ * @param message the message to color.
162
+ * @param hexFormattedColor the color to use. This should be a valid hex formatted string e.g. "#rrggbb".
163
+ */
164
+ color(message: string, hexFormattedColor: string): string;
165
+
166
+ /**
167
+ * Return the provided message so that the background is colored as primary content.
168
+ * Has no effect if {@link colorEnabled} is `false`.
169
+ */
170
+ backgroundPrimary(message: string): string;
171
+
172
+ /**
173
+ * Return the provided message so that the background is colored as secondary content.
174
+ * Has no effect if {@link colorEnabled} is `false`.
175
+ */
176
+ backgroundSecondary(message: string): string;
177
+
178
+ /**
179
+ * Return the provided message so that the background is colored as emphasised content.
180
+ * Has no effect if {@link colorEnabled} is `false`.
181
+ */
182
+ backgroundEmphasised(message: string): string;
183
+
184
+ /**
185
+ * Return the provided message so that the background is colored as selected content.
186
+ * Has no effect if {@link colorEnabled} is `false`.
187
+ */
188
+ backgroundSelected(message: string): string;
189
+
190
+ /**
191
+ * Return the provided message so that the background is yellow.
192
+ * Has no effect if {@link colorEnabled} is `false`.
193
+ */
194
+ backgroundYellow(message: string): string;
195
+
196
+ /**
197
+ * Return the provided message so that the background is orange.
198
+ * Has no effect if {@link colorEnabled} is `false`.
199
+ */
200
+ backgroundOrange(message: string): string;
201
+
202
+ /**
203
+ * Return the provided message so that the background is red.
204
+ * Has no effect if {@link colorEnabled} is `false`.
205
+ */
206
+ backgroundRed(message: string): string;
207
+
208
+ /**
209
+ * Return the provided message so that the background is magenta.
210
+ * Has no effect if {@link colorEnabled} is `false`.
211
+ */
212
+ backgroundMagenta(message: string): string;
213
+
214
+ /**
215
+ * Return the provided message so that the background is violet.
216
+ * Has no effect if {@link colorEnabled} is `false`.
217
+ */
218
+ backgroundViolet(message: string): string;
219
+
220
+ /**
221
+ * Return the provided message so that the background is blue.
222
+ * Has no effect if {@link colorEnabled} is `false`.
223
+ */
224
+ backgroundBlue(message: string): string;
225
+
226
+ /**
227
+ * Return the provided message so that the background is cyan.
228
+ * Has no effect if {@link colorEnabled} is `false`.
229
+ */
230
+ backgroundCyan(message: string): string;
231
+
232
+ /**
233
+ * Return the provided message so that the background is green.
234
+ * Has no effect if {@link colorEnabled} is `false`.
235
+ */
236
+ backgroundGreen(message: string): string;
237
+
238
+ /**
239
+ * Return the provided message so that the background is the specified color.
240
+ * Has no effect if {@link colorEnabled} is `false`.
241
+ *
242
+ * @param message the message to color.
243
+ * @param hexFormattedColor the color to use. This should be a valid hex formatted string e.g. "#rrggbb".
244
+ */
245
+ backgroundColor(message: string, hexFormattedColor: string): string;
246
+
247
+ /**
248
+ * Return the provided text wrapped in an OSC 8 hyperlink to the specified URL.
249
+ * Has no effect if {@link hyperlinksEnabled} is `false`, in which case the text is returned unchanged.
250
+ *
251
+ * @param text the text to display as the hyperlink.
252
+ * @param url the URL target of the hyperlink.
253
+ */
254
+ hyperlink(text: string, url: string): string;
255
+
256
+ /**
257
+ * Start a quoted, indented block of output. While active, every line written via {@link print},
258
+ * {@link debug}, {@link info}, {@link warn} or {@link error} is prefixed with box-drawing indent
259
+ * characters. Quotes can be nested by calling {@link startQuote} again before calling
260
+ * {@link endQuote}; each nesting level renders in its own color and adds another indent column.
261
+ *
262
+ * @param hexFormattedColor optional color for this level's indent characters, e.g. "#rrggbb".
263
+ * Defaults to the {@link secondary} theme color if not specified.
264
+ */
265
+ startQuote(hexFormattedColor?: string): void;
266
+
267
+ /**
268
+ * End the most recently started quote level (see {@link startQuote}).
269
+ *
270
+ * Throws if called without a matching {@link startQuote}.
271
+ */
272
+ endQuote(): void;
273
+
274
+ /**
275
+ * Start tracking the terminal rows occupied by subsequent writes so they can later be erased via
276
+ * {@link clearMarked}. Only one mark region can be active at a time.
277
+ *
278
+ * Throws if called while already marking.
279
+ */
280
+ startMark(): void;
281
+
282
+ /**
283
+ * Stop tracking rows for the current mark region (see {@link startMark}). The tracked row count is
284
+ * frozen; further writes are not counted. Use {@link clearMarked} to erase the tracked rows.
285
+ *
286
+ * Throws if called without a matching {@link startMark}.
287
+ */
288
+ endMark(): void;
289
+
290
+ /**
291
+ * Erase the terminal rows tracked since the last {@link startMark}/{@link endMark} pair, moving any
292
+ * following content up.
293
+ *
294
+ * @param minimumDisplayTimeMs optional minimum time (in milliseconds) that must have elapsed since
295
+ * {@link endMark} was called before the rows are erased; if less time has elapsed, waits for the
296
+ * remainder before clearing. Defaults to `0`.
297
+ *
298
+ * Throws if called without a preceding {@link endMark}.
299
+ */
300
+ clearMarked(minimumDisplayTimeMs?: number): Promise<void>;
301
+
302
+ /**
303
+ * The number of columns available on the stdout terminal.
304
+ * Defaults to 80 if the terminal width cannot be determined.
305
+ */
306
+ stdoutColumns(): number;
307
+
308
+ /**
309
+ * The number of columns available on the stderr terminal.
310
+ * Defaults to 80 if the terminal width cannot be determined.
311
+ */
312
+ stderrColumns(): number;
313
+
314
+ /**
315
+ * Print a message on `stdout`.
316
+ * Will be displayed as primary content if {@link colorEnabled} is `true`.
317
+ *
318
+ * @param message the message to output.
319
+ * @param icon optional icon to display with the message.
320
+ */
321
+ print(message: string, icon?: Icon): Promise<void>;
322
+
323
+ /**
324
+ * Print a {@link Level.DEBUG} level message on `stderr`.
325
+ * Will be displayed as secondary content if {@link colorEnabled} is `true`.
326
+ *
327
+ * @param message the message to output.
328
+ * @param icon optional icon to display with the message.
329
+ */
330
+ debug(message: string, icon?: Icon): Promise<void>;
331
+
332
+ /**
333
+ * Print an {@link Level.INFO} level message on `stderr`.
334
+ * Will be displayed as primary content if {@link colorEnabled} is `true`.
335
+ *
336
+ * @param message the message to output.
337
+ * @param icon optional icon to display with the message.
338
+ */
339
+ info(message: string, icon?: Icon): Promise<void>;
340
+
341
+ /**
342
+ * Print a {@link Level.WARN} level message on `stderr`.
343
+ * Will be displayed as yellow content if {@link colorEnabled} is `true`.
344
+ *
345
+ * @param message the message to output.
346
+ * @param icon optional icon to display with the message.
347
+ */
348
+ warn(message: string, icon?: Icon): Promise<void>;
349
+
350
+ /**
351
+ * Print an {@link Level.ERROR} level message on `stderr`.
352
+ * Will be displayed as red content if {@link colorEnabled} is `true`.
353
+ *
354
+ * @param message the message to output.
355
+ * @param icon optional icon to display with the message.
356
+ */
357
+ error(message: string, icon?: Icon): Promise<void>;
358
+
359
+ /**
360
+ * Set the output threshold {@link Level} for `stderr`.
361
+ *
362
+ * Default level is {@link Level.INFO}.
363
+ *
364
+ * @param level any message below this level will be filtered from output,
365
+ */
366
+ setLevel(level: Level): void;
367
+
368
+ /**
369
+ * Get the output threshold {@link Level} for `stderr`.
370
+ */
371
+ getLevel(): Level;
372
+
373
+ /**
374
+ * Display the spinner on `stderr`.
375
+ *
376
+ * The spinner will be displayed as emphasised content and the message will
377
+ * be displayed as primary content if {@link colorEnabled} is `true`.
378
+ *
379
+ * NOTE: The spinner and message will be displayed at {@link Level.INFO} level.
380
+ *
381
+ * NOTE: If the spinner is already displayed the message will be updated to that specified.
382
+ *
383
+ * NOTE: If any progress bars are currently displayed they will be hidden.
384
+ *
385
+ * @param message the message to output after the spinner.
386
+ * @param style optional spinner animation style, defaults to {@link SpinnerStyle.BOX}.
387
+ */
388
+ showSpinner(message: string, style?: SpinnerStyle): Promise<void>;
389
+
390
+ /**
391
+ * Hide the spinner.
392
+ *
393
+ * NOTE: Showing a progress bar will also hide the spinner.
394
+ */
395
+ hideSpinner(): Promise<void>;
396
+
397
+ /**
398
+ * Display a progress bar on `stderr`.
399
+ *
400
+ * The progress will be displayed in green if {@link colorEnabled} is `true`.
401
+ *
402
+ * NOTE: The progress bar and message will be displayed at {@link Level.INFO} level.
403
+ *
404
+ * NOTE: If the spinner is currently displayed it will be hidden.
405
+ *
406
+ * @param units the units to display for progress indication e.g. 'MB' or 'Kb'.
407
+ * @param message an optional message for the progress bar.
408
+ * @param total the total value which equates to 100% complete, defaults to `100`.
409
+ * @param current the current value which is a portion of the total value, defaults to `0`.
410
+ * @param style optional progress bar rendering style, defaults to {@link ProgressStyle.STROKE}.
411
+ *
412
+ * @return a handle to use when invoking {@link updateProgressBar}.
413
+ */
414
+ showProgressBar(
415
+ units: string,
416
+ message?: string,
417
+ total?: number,
418
+ current?: number,
419
+ style?: ProgressStyle,
420
+ ): Promise<number>;
421
+
422
+ /**
423
+ * Hides a specified progress bar.
424
+ *
425
+ * NOTE: Showing the spinner will also hide ALL progress bars.
426
+ *
427
+ * @param handle the handle referring to the progress bar to be hidden.
428
+ */
429
+ hideProgressBar(handle: number): Promise<void>;
430
+
431
+ /**
432
+ * Hides all progress bars.
433
+ *
434
+ * NOTE: Showing the spinner will also hide ALL progress bars.
435
+ */
436
+ hideAllProgressBars(): Promise<void>;
437
+
438
+ /**
439
+ * Update a specific progress bar.
440
+ *
441
+ * @param handle the handle referring to the progress bar to be updated.
442
+ * @param current the current value to set on the progress bar.
443
+ * @param message an optional message to set on the progress bar, if not specified the initially specified message will be displayed.
444
+ */
445
+ updateProgressBar(handle: number, current: number, message?: string): void;
446
+ }
@@ -0,0 +1,42 @@
1
+ import type { ArgumentSingleValueType } from "../../argument/ArgumentValueTypes.ts";
2
+
3
+ export const PROMPTER_SERVICE_ID = "@flowscripter/dynamic-cli-framework/prompter-service";
4
+
5
+ export enum PromptType {
6
+ SINGLE_SELECT = 0,
7
+ MULTI_SELECT = 1,
8
+ ACKNOWLEDGE = 2,
9
+ TOGGLE = 3,
10
+ TEXT = 4,
11
+ OPEN_URL = 5,
12
+ }
13
+
14
+ export interface PromptOption {
15
+ readonly displayValue: string;
16
+ readonly returnedValue: ArgumentSingleValueType;
17
+ readonly min?: number;
18
+ readonly max?: number;
19
+ readonly validate?: (value: ArgumentSingleValueType) => string | undefined;
20
+ }
21
+
22
+ export interface Prompt {
23
+ readonly name: string;
24
+ readonly promptText: string;
25
+ readonly type: PromptType;
26
+ readonly description?: string;
27
+ readonly defaultOption?: PromptOption;
28
+ readonly options: ReadonlyArray<PromptOption>;
29
+ }
30
+
31
+ export interface PromptResult {
32
+ readonly name: string;
33
+ readonly value: ArgumentSingleValueType | ReadonlyArray<ArgumentSingleValueType>;
34
+ }
35
+
36
+ export default interface PrompterService {
37
+ promptEnabled: boolean;
38
+
39
+ prompt(prompt: Prompt): Promise<PromptResult>;
40
+
41
+ promptAll(prompts: ReadonlyArray<Prompt>): Promise<ReadonlyArray<PromptResult>>;
42
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Internal service providing secret storage via OS-native credential stores.
3
+ * Not registered in Context -- used internally by `DefaultKeyValueService` (see dynamic-cli-framework).
4
+ */
5
+ export default interface SecretService {
6
+ /**
7
+ * Store a secret value. Constructs the Bun secret name from the current scope and key.
8
+ *
9
+ * @returns the constructed Bun secret name (used as part of the sentinel value in the key-value Map).
10
+ */
11
+ setSecret(key: string, value: string): Promise<string>;
12
+
13
+ /**
14
+ * Retrieve a secret value by its full Bun secret name.
15
+ */
16
+ getSecret(bunSecretName: string): Promise<string | null>;
17
+
18
+ /**
19
+ * Delete a secret by its full Bun secret name.
20
+ */
21
+ deleteSecret(bunSecretName: string): Promise<boolean>;
22
+
23
+ /**
24
+ * Check if a secret exists by its full Bun secret name.
25
+ */
26
+ hasSecret(bunSecretName: string): Promise<boolean>;
27
+ }
@@ -0,0 +1,27 @@
1
+ export const SHUTDOWN_SERVICE_ID = "@flowscripter/dynamic-cli-framework/shutdown-service";
2
+
3
+ /**
4
+ * Service allowing registration of callbacks for CLI shutdown.
5
+ */
6
+ export default interface ShutdownService {
7
+ /**
8
+ * Register a callback to be invoked during graceful shutdown.
9
+ */
10
+ addShutdownListener(callback: () => Promise<void>): void;
11
+
12
+ /**
13
+ * Enter long-running mode where the first Ctrl-C sets a cooperative flag
14
+ * instead of exiting, and a third Ctrl-C forces exit.
15
+ */
16
+ enterLongRunningMode(): void;
17
+
18
+ /**
19
+ * Leave long-running mode, restoring default single Ctrl-C exit behavior.
20
+ */
21
+ leaveLongRunningMode(): void;
22
+
23
+ /**
24
+ * True once shutdown has been requested (e.g. first Ctrl-C in long-running mode).
25
+ */
26
+ readonly isShutdownRequested: boolean;
27
+ }
@@ -0,0 +1,54 @@
1
+ import type { LanguageFn as HighlightSyntax } from "highlight.js";
2
+
3
+ export const SYNTAX_HIGHLIGHTER_SERVICE_ID =
4
+ "@flowscripter/dynamic-cli-framework/syntax-highlighter-service";
5
+
6
+ /**
7
+ * Color scheme for syntax highlighting.
8
+ *
9
+ * The keys are the names of the defined [highlight.js scopes](https://highlightjs.readthedocs.io/en/latest/css-classes-reference.html).
10
+ *
11
+ * The values are colors expressed as a hex formatted string e.g. "#rrggbb".
12
+ *
13
+ * The scheme does not need to list all scopes exhaustively.
14
+ */
15
+ export type ColorScheme = Record<string, string>;
16
+
17
+ /**
18
+ * Service providing syntax based color highlighting of text for the CLI using [highlight.js](https://github.com/highlightjs/highlight.js).
19
+ */
20
+ export default interface SyntaxHighlighterService {
21
+ /**
22
+ * Register a new syntax.
23
+ *
24
+ * The recommended way to define a new language syntax is to follow the instructions here:
25
+ *
26
+ * * https://highlightjs.readthedocs.io/en/latest/language-contribution.html
27
+ * * https://highlightjs.readthedocs.io/en/latest/building-testing.html
28
+ * * https://github.com/highlightjs/highlight.js/blob/main/docs/language-guide.rst
29
+ *
30
+ * There is a list of already defined languages available for import here:
31
+ *
32
+ * https://github.com/highlightjs/highlight.js/blob/main/SUPPORTED_LANGUAGES.md
33
+ *
34
+ * @param syntaxName the name used to refer to the syntax.
35
+ * @param syntaxDefinition the definition for the syntax conforming to the Highlight JS
36
+ * language definition syntax.
37
+ */
38
+ registerSyntax(syntaxName: string, syntaxDefinition: HighlightSyntax): void;
39
+
40
+ /**
41
+ * Return the names of the currently registered syntaxes.
42
+ */
43
+ getRegisteredSyntaxes(): ReadonlyArray<string>;
44
+
45
+ /**
46
+ * Return a syntactically highlighted version of the provided text using the specified syntax.
47
+ * The returned text will include appropriate color styling. An optional {@link ColorScheme} can be provided.
48
+ *
49
+ * @param text the text to highlight.
50
+ * @param syntaxName the syntax to use.
51
+ * @param colorScheme the color scheme to use.
52
+ */
53
+ highlight(text: string, syntaxName: string, colorScheme?: ColorScheme): string;
54
+ }
@@ -0,0 +1,67 @@
1
+ import type {
2
+ CellOptions,
3
+ ColumnOptions,
4
+ RowOptions,
5
+ TableOptions,
6
+ } from "./TableGeneratorService.ts";
7
+
8
+ export default class Table {
9
+ readonly rowCount: number;
10
+ readonly columnCount: number;
11
+ readonly options: TableOptions;
12
+
13
+ readonly #columnOptions: Map<number, ColumnOptions> = new Map();
14
+ readonly #rowOptions: Map<number, RowOptions> = new Map();
15
+ readonly #cells: Map<string, { contents: string; options?: CellOptions }> = new Map();
16
+
17
+ constructor(rowCount: number, columnCount: number, options?: TableOptions) {
18
+ this.rowCount = rowCount;
19
+ this.columnCount = columnCount;
20
+ this.options = options ?? {};
21
+ }
22
+
23
+ row(rowIndex: number, rowOptions: RowOptions): Table {
24
+ if (rowIndex < 0 || rowIndex >= this.rowCount) {
25
+ throw new Error(`Row index ${rowIndex} out of bounds [0, ${this.rowCount})`);
26
+ }
27
+ this.#rowOptions.set(rowIndex, rowOptions);
28
+ return this;
29
+ }
30
+
31
+ column(columnIndex: number, columnOptions: ColumnOptions): Table {
32
+ if (columnIndex < 0 || columnIndex >= this.columnCount) {
33
+ throw new Error(`Column index ${columnIndex} out of bounds [0, ${this.columnCount})`);
34
+ }
35
+ this.#columnOptions.set(columnIndex, columnOptions);
36
+ return this;
37
+ }
38
+
39
+ cell(rowIndex: number, columnIndex: number, contents: string, cellOptions?: CellOptions): Table {
40
+ if (rowIndex < 0 || rowIndex >= this.rowCount) {
41
+ throw new Error(`Row index ${rowIndex} out of bounds [0, ${this.rowCount})`);
42
+ }
43
+ if (columnIndex < 0 || columnIndex >= this.columnCount) {
44
+ throw new Error(`Column index ${columnIndex} out of bounds [0, ${this.columnCount})`);
45
+ }
46
+ this.#cells.set(`${rowIndex},${columnIndex}`, {
47
+ contents,
48
+ options: cellOptions,
49
+ });
50
+ return this;
51
+ }
52
+
53
+ getColumnOptions(columnIndex: number): ColumnOptions | undefined {
54
+ return this.#columnOptions.get(columnIndex);
55
+ }
56
+
57
+ getRowOptions(rowIndex: number): RowOptions | undefined {
58
+ return this.#rowOptions.get(rowIndex);
59
+ }
60
+
61
+ getCell(
62
+ rowIndex: number,
63
+ columnIndex: number,
64
+ ): { contents: string; options?: CellOptions } | undefined {
65
+ return this.#cells.get(`${rowIndex},${columnIndex}`);
66
+ }
67
+ }
@@ -0,0 +1,39 @@
1
+ export const TABLE_GENERATOR_SERVICE_ID =
2
+ "@flowscripter/dynamic-cli-framework/table-generator-service";
3
+
4
+ export enum Align {
5
+ LEFT = 0,
6
+ CENTER = 1,
7
+ RIGHT = 2,
8
+ }
9
+
10
+ export interface TableOptions {
11
+ border?: boolean;
12
+ borderColor?: string;
13
+ borderBackgroundColor?: string;
14
+ padding?: number;
15
+ maxWidth?: number;
16
+ align?: Align;
17
+ }
18
+
19
+ export interface ColumnOptions {
20
+ flexWeight?: number;
21
+ minWidth?: number;
22
+ maxWidth?: number;
23
+ align?: Align;
24
+ }
25
+
26
+ export interface RowOptions {
27
+ align?: Align;
28
+ }
29
+
30
+ export interface CellOptions {
31
+ align?: Align;
32
+ }
33
+
34
+ export default interface TableGeneratorService {
35
+ createTable(rowCount: number, columnCount: number, options?: TableOptions): Table;
36
+ render(table: Table): string;
37
+ }
38
+
39
+ import type Table from "./Table.ts";