@twin.org/cli-core 0.0.2-next.8 → 0.0.2

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 (46) hide show
  1. package/README.md +2 -2
  2. package/dist/es/cliBase.js +122 -0
  3. package/dist/es/cliBase.js.map +1 -0
  4. package/dist/es/cliDisplay.js +166 -0
  5. package/dist/es/cliDisplay.js.map +1 -0
  6. package/dist/es/cliOptions.js +36 -0
  7. package/dist/es/cliOptions.js.map +1 -0
  8. package/dist/es/cliParam.js +248 -0
  9. package/dist/es/cliParam.js.map +1 -0
  10. package/dist/es/cliUtils.js +235 -0
  11. package/dist/es/cliUtils.js.map +1 -0
  12. package/dist/es/commands/global.js +61 -0
  13. package/dist/es/commands/global.js.map +1 -0
  14. package/dist/es/index.js +14 -0
  15. package/dist/es/index.js.map +1 -0
  16. package/dist/es/models/ICliOptions.js +2 -0
  17. package/dist/es/models/ICliOptions.js.map +1 -0
  18. package/dist/es/models/ICliOutputOptionsConsole.js +2 -0
  19. package/dist/es/models/ICliOutputOptionsConsole.js.map +1 -0
  20. package/dist/es/models/ICliOutputOptionsEnv.js +2 -0
  21. package/dist/es/models/ICliOutputOptionsEnv.js.map +1 -0
  22. package/dist/es/models/ICliOutputOptionsJson.js +2 -0
  23. package/dist/es/models/ICliOutputOptionsJson.js.map +1 -0
  24. package/dist/es/models/cliOutputOptions.js +2 -0
  25. package/dist/es/models/cliOutputOptions.js.map +1 -0
  26. package/dist/types/cliBase.d.ts +1 -1
  27. package/dist/types/cliDisplay.d.ts +5 -0
  28. package/dist/types/cliParam.d.ts +10 -9
  29. package/dist/types/index.d.ts +11 -11
  30. package/dist/types/models/cliOutputOptions.d.ts +3 -3
  31. package/docs/changelog.md +1197 -71
  32. package/docs/examples.md +82 -1
  33. package/docs/reference/classes/CLIBase.md +3 -3
  34. package/docs/reference/classes/CLIDisplay.md +46 -26
  35. package/docs/reference/classes/CLIOptions.md +1 -1
  36. package/docs/reference/classes/CLIParam.md +97 -85
  37. package/docs/reference/classes/CLIUtils.md +25 -25
  38. package/docs/reference/interfaces/ICliOptions.md +12 -12
  39. package/docs/reference/interfaces/ICliOutputOptionsConsole.md +1 -1
  40. package/docs/reference/interfaces/ICliOutputOptionsEnv.md +3 -3
  41. package/docs/reference/interfaces/ICliOutputOptionsJson.md +3 -3
  42. package/locales/.validate-ignore +1 -0
  43. package/locales/en.json +0 -1
  44. package/package.json +28 -16
  45. package/dist/cjs/index.cjs +0 -878
  46. package/dist/esm/index.mjs +0 -849
package/docs/examples.md CHANGED
@@ -1 +1,82 @@
1
- # @twin.org/cli-core - Examples
1
+ # CLI Core Examples
2
+
3
+ Use these snippets to compose clear command line workflows with consistent output, argument parsing and file handling.
4
+
5
+ ## CLIDisplay
6
+
7
+ ```typescript
8
+ import { CLIDisplay } from '@twin.org/cli-core';
9
+
10
+ CLIDisplay.header('Data Import', '1.2.0');
11
+ CLIDisplay.section('Validation');
12
+ CLIDisplay.value('Records', 128);
13
+ CLIDisplay.warning('2 rows have missing optional fields');
14
+ CLIDisplay.done();
15
+ ```
16
+
17
+ ## CLIParam
18
+
19
+ ```typescript
20
+ import { CLIParam } from '@twin.org/cli-core';
21
+
22
+ const parsedCount = CLIParam.integer('count', '25');
23
+ const parsedDebug = CLIParam.boolean('debug', 'true');
24
+ const parsedUrl = CLIParam.url('endpoint', 'https://api.example.org');
25
+
26
+ console.log(parsedCount + 1); // 26
27
+ console.log(parsedDebug); // true
28
+ console.log(parsedUrl.host); // api.example.org
29
+ ```
30
+
31
+ ## CLIBase
32
+
33
+ ```typescript
34
+ import { CLIBase } from '@twin.org/cli-core';
35
+ import type { Command } from 'commander';
36
+
37
+ class ToolCli extends CLIBase {
38
+ protected getCommands(program: Command): Command[] {
39
+ return [program.command('status').action(() => {})];
40
+ }
41
+ }
42
+
43
+ const cli = new ToolCli();
44
+ const exitCode = await cli.execute(
45
+ {
46
+ appName: 'tool-cli',
47
+ title: 'Tool CLI',
48
+ version: '1.0.0'
49
+ },
50
+ './locales',
51
+ ['node', 'tool-cli', 'status']
52
+ );
53
+
54
+ console.log(exitCode); // 0
55
+ ```
56
+
57
+ ## CLIUtils
58
+
59
+ ```typescript
60
+ import { CLIUtils } from '@twin.org/cli-core';
61
+
62
+ console.log(await CLIUtils.fileExists('./config/import.json')); // true
63
+ const config = await CLIUtils.readJsonFile<{ source: string }>('./config/import.json');
64
+ await CLIUtils.writeEnvFile('./dist/import.env', {
65
+ SOURCE: config.source
66
+ });
67
+ console.log(config.source); // ./data/source.json
68
+ ```
69
+
70
+ ## CLIOptions
71
+
72
+ ```typescript
73
+ import { CLIOptions } from '@twin.org/cli-core';
74
+
75
+ const options = new CLIOptions();
76
+
77
+ options.output({
78
+ json: './dist/output.json'
79
+ });
80
+
81
+ console.log(options.toObject().json); // ./dist/output.json
82
+ ```
@@ -14,7 +14,7 @@ The main entry point for the CLI.
14
14
 
15
15
  ## Methods
16
16
 
17
- ### execute()
17
+ ### execute() {#execute}
18
18
 
19
19
  > **execute**(`options`, `localesDirectory`, `argv`): `Promise`\<`number`\>
20
20
 
@@ -48,7 +48,7 @@ The exit code.
48
48
 
49
49
  ***
50
50
 
51
- ### configureRoot()
51
+ ### configureRoot() {#configureroot}
52
52
 
53
53
  > `protected` **configureRoot**(`program`): `void`
54
54
 
@@ -68,7 +68,7 @@ The root program command.
68
68
 
69
69
  ***
70
70
 
71
- ### getCommands()
71
+ ### getCommands() {#getcommands}
72
72
 
73
73
  > `protected` **getCommands**(`program`): `Command`[]
74
74
 
@@ -14,7 +14,7 @@ Display utilities for the CLI.
14
14
 
15
15
  ## Properties
16
16
 
17
- ### write()
17
+ ### write {#write}
18
18
 
19
19
  > `static` **write**: (`buffer`) => `void`
20
20
 
@@ -24,9 +24,9 @@ The default output method for writing standard messages.
24
24
 
25
25
  ##### buffer
26
26
 
27
- The message to output.
27
+ `string` \| `Uint8Array`\<`ArrayBufferLike`\>
28
28
 
29
- `string` | `Uint8Array`\<`ArrayBufferLike`\>
29
+ The message to output.
30
30
 
31
31
  #### Returns
32
32
 
@@ -34,7 +34,7 @@ The message to output.
34
34
 
35
35
  ***
36
36
 
37
- ### writeError()
37
+ ### writeError {#writeerror}
38
38
 
39
39
  > `static` **writeError**: (`buffer`) => `void`
40
40
 
@@ -44,9 +44,9 @@ The default output method for writing error messages.
44
44
 
45
45
  ##### buffer
46
46
 
47
- The message to output.
47
+ `string` \| `Uint8Array`\<`ArrayBufferLike`\>
48
48
 
49
- `string` | `Uint8Array`\<`ArrayBufferLike`\>
49
+ The message to output.
50
50
 
51
51
  #### Returns
52
52
 
@@ -54,7 +54,7 @@ The message to output.
54
54
 
55
55
  ***
56
56
 
57
- ### clearLine()
57
+ ### clearLine {#clearline}
58
58
 
59
59
  > `static` **clearLine**: () => `void`
60
60
 
@@ -66,7 +66,7 @@ The default output method for clearing the current line.
66
66
 
67
67
  ## Methods
68
68
 
69
- ### header()
69
+ ### header() {#header}
70
70
 
71
71
  > `static` **header**(`title`, `version`, `icon`): `void`
72
72
 
@@ -98,9 +98,9 @@ The icon for the CLI.
98
98
 
99
99
  ***
100
100
 
101
- ### error()
101
+ ### error() {#error}
102
102
 
103
- > `static` **error**(`error`, `lineBreaks`): `void`
103
+ > `static` **error**(`error`, `lineBreaks?`): `void`
104
104
 
105
105
  Display an error message.
106
106
 
@@ -112,7 +112,7 @@ Display an error message.
112
112
 
113
113
  The error to display.
114
114
 
115
- ##### lineBreaks
115
+ ##### lineBreaks?
116
116
 
117
117
  `boolean` = `true`
118
118
 
@@ -124,7 +124,27 @@ Whether to add a line break after the error.
124
124
 
125
125
  ***
126
126
 
127
- ### section()
127
+ ### errorMessage() {#errormessage}
128
+
129
+ > `static` **errorMessage**(`error`): `void`
130
+
131
+ Display an error message in simple form.
132
+
133
+ #### Parameters
134
+
135
+ ##### error
136
+
137
+ `string`
138
+
139
+ The error to display.
140
+
141
+ #### Returns
142
+
143
+ `void`
144
+
145
+ ***
146
+
147
+ ### section() {#section}
128
148
 
129
149
  > `static` **section**(`label`): `void`
130
150
 
@@ -144,9 +164,9 @@ The label for the section.
144
164
 
145
165
  ***
146
166
 
147
- ### value()
167
+ ### value() {#value}
148
168
 
149
- > `static` **value**(`label`, `value`, `indentLevel`): `void`
169
+ > `static` **value**(`label`, `value`, `indentLevel?`): `void`
150
170
 
151
171
  Display a value with a label.
152
172
 
@@ -164,7 +184,7 @@ The label for the value.
164
184
 
165
185
  The value to display.
166
186
 
167
- ##### indentLevel
187
+ ##### indentLevel?
168
188
 
169
189
  `number` = `0`
170
190
 
@@ -176,7 +196,7 @@ The level of indentation.
176
196
 
177
197
  ***
178
198
 
179
- ### task()
199
+ ### task() {#task}
180
200
 
181
201
  > `static` **task**(`label`, `task?`): `void`
182
202
 
@@ -202,7 +222,7 @@ The task to display.
202
222
 
203
223
  ***
204
224
 
205
- ### break()
225
+ ### break() {#break}
206
226
 
207
227
  > `static` **break**(): `void`
208
228
 
@@ -214,7 +234,7 @@ Display a break.
214
234
 
215
235
  ***
216
236
 
217
- ### json()
237
+ ### json() {#json}
218
238
 
219
239
  > `static` **json**(`obj`): `void`
220
240
 
@@ -234,7 +254,7 @@ The object to display.
234
254
 
235
255
  ***
236
256
 
237
- ### warning()
257
+ ### warning() {#warning}
238
258
 
239
259
  > `static` **warning**(`label`): `void`
240
260
 
@@ -254,7 +274,7 @@ The label for the warning.
254
274
 
255
275
  ***
256
276
 
257
- ### done()
277
+ ### done() {#done}
258
278
 
259
279
  > `static` **done**(): `void`
260
280
 
@@ -266,27 +286,27 @@ Display the processing is done.
266
286
 
267
287
  ***
268
288
 
269
- ### spinnerStart()
289
+ ### spinnerStart() {#spinnerstart}
270
290
 
271
- > `static` **spinnerStart**(`i18nMessage`, `spinnerCharacters`, `interval`): `void`
291
+ > `static` **spinnerStart**(`i18nMessage?`, `spinnerCharacters?`, `interval?`): `void`
272
292
 
273
293
  Start the spinner.
274
294
 
275
295
  #### Parameters
276
296
 
277
- ##### i18nMessage
297
+ ##### i18nMessage?
278
298
 
279
299
  `string` = `"cli.progress.pleaseWait"`
280
300
 
281
301
  The message to display with the spinner.
282
302
 
283
- ##### spinnerCharacters
303
+ ##### spinnerCharacters?
284
304
 
285
305
  `string`[] = `...`
286
306
 
287
307
  The characters to use in the spinner.
288
308
 
289
- ##### interval
309
+ ##### interval?
290
310
 
291
311
  `number` = `100`
292
312
 
@@ -298,7 +318,7 @@ The interval for the spinner.
298
318
 
299
319
  ***
300
320
 
301
- ### spinnerStop()
321
+ ### spinnerStop() {#spinnerstop}
302
322
 
303
323
  > `static` **spinnerStop**(): `void`
304
324
 
@@ -14,7 +14,7 @@ Utilities for getting standard options.
14
14
 
15
15
  ## Methods
16
16
 
17
- ### output()
17
+ ### output() {#output}
18
18
 
19
19
  > `static` **output**(`command`, `opts`): `void`
20
20