@twin.org/cli-core 0.0.2-next.19 → 0.0.2-next.21

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.
@@ -10,7 +10,6 @@ var dotenv = require('dotenv');
10
10
  var node_child_process = require('node:child_process');
11
11
  var node_fs = require('node:fs');
12
12
  var promises = require('node:fs/promises');
13
- var crypto = require('@twin.org/crypto');
14
13
 
15
14
  function _interopNamespaceDefault(e) {
16
15
  var n = Object.create(null);
@@ -87,6 +86,15 @@ class CLIDisplay {
87
86
  CLIDisplay.writeError("\n");
88
87
  }
89
88
  }
89
+ /**
90
+ * Display an error message in simple form.
91
+ * @param error The error to display.
92
+ */
93
+ static errorMessage(error) {
94
+ CLIDisplay.writeError("❗ ");
95
+ CLIDisplay.writeError(chalk.red(error));
96
+ CLIDisplay.writeError("\n");
97
+ }
90
98
  /**
91
99
  * Display a section.
92
100
  * @param label The label for the section.
@@ -538,6 +546,10 @@ class CLIBase {
538
546
  catch (error) {
539
547
  CLIDisplay.spinnerStop();
540
548
  let exitCode;
549
+ // We have no control over the response from commander
550
+ // so we have to do some checking and coercion here
551
+ // to get a valid exit code.
552
+ // eslint-disable-next-line no-restricted-syntax
541
553
  if (error instanceof Error) {
542
554
  // This error could be the exit code we errored with
543
555
  // from the exitOverride so parse and resolve with it
@@ -635,6 +647,8 @@ class CLIParam {
635
647
  static env(optionName, optionValue, allowEnvVar) {
636
648
  if (allowEnvVar && optionValue?.startsWith("!")) {
637
649
  const envValueName = optionValue.slice(1);
650
+ // This is reading from an env var so it really has no choice
651
+ // eslint-disable-next-line no-restricted-syntax
638
652
  const envValue = process.env[envValueName];
639
653
  if (core.Is.empty(envValue)) {
640
654
  throw new core.GeneralError("commands", "commands.common.missingEnv", {
@@ -861,24 +875,6 @@ class CLIParam {
861
875
  value: optionValue
862
876
  });
863
877
  }
864
- /**
865
- * Check the option to see if it exists and is bech32.
866
- * @param optionName The name of the option.
867
- * @param optionValue The option value.
868
- * @param allowEnvVar Allow the option to be read from an env var.
869
- * @returns The final option value.
870
- * @throws An error if the option is invalid.
871
- */
872
- static bech32(optionName, optionValue, allowEnvVar = true) {
873
- optionValue = CLIParam.env(optionName, optionValue, allowEnvVar);
874
- if (crypto.Bech32.isBech32(optionValue)) {
875
- return optionValue;
876
- }
877
- throw new core.GeneralError("commands", "commands.common.optionInvalidBech32", {
878
- option: optionName,
879
- value: optionValue
880
- });
881
- }
882
878
  }
883
879
 
884
880
  exports.CLIBase = CLIBase;
@@ -8,7 +8,6 @@ import * as dotenv from 'dotenv';
8
8
  import { exec, spawn } from 'node:child_process';
9
9
  import { statSync, accessSync, readFileSync } from 'node:fs';
10
10
  import { stat, access, readFile, mkdir, writeFile } from 'node:fs/promises';
11
- import { Bech32 } from '@twin.org/crypto';
12
11
 
13
12
  // Copyright 2024 IOTA Stiftung.
14
13
  // SPDX-License-Identifier: Apache-2.0.
@@ -66,6 +65,15 @@ class CLIDisplay {
66
65
  CLIDisplay.writeError("\n");
67
66
  }
68
67
  }
68
+ /**
69
+ * Display an error message in simple form.
70
+ * @param error The error to display.
71
+ */
72
+ static errorMessage(error) {
73
+ CLIDisplay.writeError("❗ ");
74
+ CLIDisplay.writeError(chalk.red(error));
75
+ CLIDisplay.writeError("\n");
76
+ }
69
77
  /**
70
78
  * Display a section.
71
79
  * @param label The label for the section.
@@ -517,6 +525,10 @@ class CLIBase {
517
525
  catch (error) {
518
526
  CLIDisplay.spinnerStop();
519
527
  let exitCode;
528
+ // We have no control over the response from commander
529
+ // so we have to do some checking and coercion here
530
+ // to get a valid exit code.
531
+ // eslint-disable-next-line no-restricted-syntax
520
532
  if (error instanceof Error) {
521
533
  // This error could be the exit code we errored with
522
534
  // from the exitOverride so parse and resolve with it
@@ -614,6 +626,8 @@ class CLIParam {
614
626
  static env(optionName, optionValue, allowEnvVar) {
615
627
  if (allowEnvVar && optionValue?.startsWith("!")) {
616
628
  const envValueName = optionValue.slice(1);
629
+ // This is reading from an env var so it really has no choice
630
+ // eslint-disable-next-line no-restricted-syntax
617
631
  const envValue = process.env[envValueName];
618
632
  if (Is.empty(envValue)) {
619
633
  throw new GeneralError("commands", "commands.common.missingEnv", {
@@ -840,24 +854,6 @@ class CLIParam {
840
854
  value: optionValue
841
855
  });
842
856
  }
843
- /**
844
- * Check the option to see if it exists and is bech32.
845
- * @param optionName The name of the option.
846
- * @param optionValue The option value.
847
- * @param allowEnvVar Allow the option to be read from an env var.
848
- * @returns The final option value.
849
- * @throws An error if the option is invalid.
850
- */
851
- static bech32(optionName, optionValue, allowEnvVar = true) {
852
- optionValue = CLIParam.env(optionName, optionValue, allowEnvVar);
853
- if (Bech32.isBech32(optionValue)) {
854
- return optionValue;
855
- }
856
- throw new GeneralError("commands", "commands.common.optionInvalidBech32", {
857
- option: optionName,
858
- value: optionValue
859
- });
860
- }
861
857
  }
862
858
 
863
859
  export { CLIBase, CLIDisplay, CLIOptions, CLIParam, CLIUtils, addGlobalOptions, handleGlobalOptions, initGlobalOptions, initLocales };
@@ -29,6 +29,11 @@ export declare class CLIDisplay {
29
29
  * @param lineBreaks Whether to add a line break after the error.
30
30
  */
31
31
  static error(error: unknown, lineBreaks?: boolean): void;
32
+ /**
33
+ * Display an error message in simple form.
34
+ * @param error The error to display.
35
+ */
36
+ static errorMessage(error: string): void;
32
37
  /**
33
38
  * Display a section.
34
39
  * @param label The label for the section.
@@ -108,13 +108,4 @@ export declare class CLIParam {
108
108
  * @throws An error if the option is invalid.
109
109
  */
110
110
  static hexBase64(optionName: string, optionValue: string | undefined, allowEnvVar?: boolean): Uint8Array;
111
- /**
112
- * Check the option to see if it exists and is bech32.
113
- * @param optionName The name of the option.
114
- * @param optionValue The option value.
115
- * @param allowEnvVar Allow the option to be read from an env var.
116
- * @returns The final option value.
117
- * @throws An error if the option is invalid.
118
- */
119
- static bech32(optionName: string, optionValue: string | undefined, allowEnvVar?: boolean): string;
120
111
  }
package/docs/changelog.md CHANGED
@@ -1,5 +1,42 @@
1
1
  # @twin.org/cli-core - Changelog
2
2
 
3
+ ## [0.0.2-next.21](https://github.com/twinfoundation/framework/compare/cli-core-v0.0.2-next.20...cli-core-v0.0.2-next.21) (2025-10-09)
4
+
5
+
6
+ ### Features
7
+
8
+ * locales validation ([#197](https://github.com/twinfoundation/framework/issues/197)) ([55fdadb](https://github.com/twinfoundation/framework/commit/55fdadb13595ce0047f787bd1d4135d429a99f12))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/core bumped from 0.0.2-next.20 to 0.0.2-next.21
16
+ * @twin.org/nameof bumped from 0.0.2-next.20 to 0.0.2-next.21
17
+ * devDependencies
18
+ * @twin.org/nameof-transformer bumped from 0.0.2-next.20 to 0.0.2-next.21
19
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.20 to 0.0.2-next.21
20
+
21
+ ## [0.0.2-next.20](https://github.com/twinfoundation/framework/compare/cli-core-v0.0.2-next.19...cli-core-v0.0.2-next.20) (2025-10-02)
22
+
23
+
24
+ ### Miscellaneous Chores
25
+
26
+ * **cli-core:** Synchronize repo versions
27
+
28
+
29
+ ### Dependencies
30
+
31
+ * The following workspace dependencies were updated
32
+ * dependencies
33
+ * @twin.org/core bumped from 0.0.2-next.19 to 0.0.2-next.20
34
+ * @twin.org/crypto bumped from 0.0.2-next.19 to 0.0.2-next.20
35
+ * @twin.org/nameof bumped from 0.0.2-next.19 to 0.0.2-next.20
36
+ * devDependencies
37
+ * @twin.org/nameof-transformer bumped from 0.0.2-next.19 to 0.0.2-next.20
38
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.19 to 0.0.2-next.20
39
+
3
40
  ## [0.0.2-next.19](https://github.com/twinfoundation/framework/compare/cli-core-v0.0.2-next.18...cli-core-v0.0.2-next.19) (2025-09-30)
4
41
 
5
42
 
@@ -124,6 +124,26 @@ Whether to add a line break after the error.
124
124
 
125
125
  ***
126
126
 
127
+ ### 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
+
127
147
  ### section()
128
148
 
129
149
  > `static` **section**(`label`): `void`
@@ -477,41 +477,3 @@ The final option value.
477
477
  #### Throws
478
478
 
479
479
  An error if the option is invalid.
480
-
481
- ***
482
-
483
- ### bech32()
484
-
485
- > `static` **bech32**(`optionName`, `optionValue`, `allowEnvVar`): `string`
486
-
487
- Check the option to see if it exists and is bech32.
488
-
489
- #### Parameters
490
-
491
- ##### optionName
492
-
493
- `string`
494
-
495
- The name of the option.
496
-
497
- ##### optionValue
498
-
499
- The option value.
500
-
501
- `undefined` | `string`
502
-
503
- ##### allowEnvVar
504
-
505
- `boolean` = `true`
506
-
507
- Allow the option to be read from an env var.
508
-
509
- #### Returns
510
-
511
- `string`
512
-
513
- The final option value.
514
-
515
- #### Throws
516
-
517
- An error if the option is invalid.
@@ -0,0 +1 @@
1
+ ^commander.help$
package/locales/en.json CHANGED
@@ -6,7 +6,6 @@
6
6
  "optionInvalidHex": "The \"{option}\" does not appear to be hex. \"{value}\"",
7
7
  "optionInvalidBase64": "The \"{option}\" does not appear to be base64. \"{value}\"",
8
8
  "optionInvalidHexBase64": "The \"{option}\" does not appear to be hex or base64. \"{value}\"",
9
- "optionInvalidBech32": "The \"{option}\" does not appear to be bech32. \"{value}\"",
10
9
  "optionMinValue": "The \"{option}\" option must be greater than or equal to {minValue}, it is {value}.",
11
10
  "optionMaxValue": "The \"{option}\" option must be less than or equal to {maxValue}, it is {value}."
12
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/cli-core",
3
- "version": "0.0.2-next.19",
3
+ "version": "0.0.2-next.21",
4
4
  "description": "Core classes for building a CLI",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,9 +14,8 @@
14
14
  "node": ">=20.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "@twin.org/core": "0.0.2-next.19",
18
- "@twin.org/crypto": "0.0.2-next.19",
19
- "@twin.org/nameof": "0.0.2-next.19",
17
+ "@twin.org/core": "0.0.2-next.21",
18
+ "@twin.org/nameof": "0.0.2-next.21",
20
19
  "chalk": "5.6.2",
21
20
  "commander": "14.0.1",
22
21
  "dotenv": "17.2.2"
@@ -37,5 +36,19 @@
37
36
  "dist/types",
38
37
  "locales",
39
38
  "docs"
40
- ]
39
+ ],
40
+ "keywords": [
41
+ "twin",
42
+ "trade",
43
+ "iota",
44
+ "framework",
45
+ "blockchain",
46
+ "core",
47
+ "foundation",
48
+ "utilities"
49
+ ],
50
+ "bugs": {
51
+ "url": "git+https://github.com/twinfoundation/framework/issues"
52
+ },
53
+ "homepage": "https://twindev.org"
41
54
  }