@twin.org/cli-core 0.0.3-next.37 → 0.0.3-next.39

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.
@@ -54,9 +54,9 @@ export class CLIParam {
54
54
  * @throws An error if the option is invalid.
55
55
  */
56
56
  static arrayOneOf(optionName, optionValue, validValues, allowEnvVar = true) {
57
- optionValue = CLIParam.env(optionName, optionValue, allowEnvVar);
58
- Guards.arrayOneOf("commands", optionName, optionValue, validValues);
59
- return optionValue;
57
+ const stringValue = CLIParam.env(optionName, optionValue, allowEnvVar);
58
+ Guards.arrayOneOf("commands", optionName, stringValue, validValues);
59
+ return stringValue;
60
60
  }
61
61
  /**
62
62
  * Check the option to see if it is a url.
@@ -1 +1 @@
1
- {"version":3,"file":"cliParam.js","sourceRoot":"","sources":["../../src/cliParam.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAElF;;GAEG;AACH,MAAM,OAAO,QAAQ;IACpB;;;;;;;OAOG;IACI,MAAM,CAAC,GAAG,CAChB,UAAkB,EAClB,WAA+B,EAC/B,WAAoB;QAEpB,IAAI,WAAW,IAAI,WAAW,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YACjD,MAAM,YAAY,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAC1C,6DAA6D;YAC7D,gDAAgD;YAChD,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;YAC3C,IAAI,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACxB,MAAM,IAAI,YAAY,CAAC,UAAU,EAAE,4BAA4B,EAAE;oBAChE,MAAM,EAAE,UAAU;oBAClB,KAAK,EAAE,YAAY;iBACnB,CAAC,CAAC;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AC,CAAC;QAEjE,IAAI,EAAE,CAAC,YAAY,CAAC,WAAW,CAAC,EAAE,CAAC;YAClC,OAAO,SAAS,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;QAC7C,CAAC;QACD,MAAM,IAAI,YAAY,CAAC,UAAU,EAAE,qCAAqC,EAAE;YACzE,MAAM,EAAE,UAAU;YAClB,KAAK,EAAE,WAAW;SAClB,CAAC,CAAC;IACJ,CAAC;IAED;;;;;;;OAOG;IACI,MAAM,CAAC,SAAS,CACtB,UAAkB,EAClB,WAA+B,EAC/B,cAAuB,IAAI;QAE3B,WAAW,GAAG,QAAQ,CAAC,GAAG,CAAC,UAAU,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;QAEjE,IAAI,EAAE,CAAC,SAAS,CAAC,WAAW,EAAE,IAAI,CAAC,EAAE,CAAC;YACrC,OAAO,SAAS,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QAC1C,CAAC;aAAM,IAAI,EAAE,CAAC,YAAY,CAAC,WAAW,CAAC,EAAE,CAAC;YACzC,OAAO,SAAS,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;QAC7C,CAAC;QACD,MAAM,IAAI,YAAY,CAAC,UAAU,EAAE,wCAAwC,EAAE;YAC5E,MAAM,EAAE,UAAU;YAClB,KAAK,EAAE,WAAW;SAClB,CAAC,CAAC;IACJ,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Coerce, Converter, GeneralError, Guards, Is, Url } from \"@twin.org/core\";\n\n/**\n * Parameter utilities for the CLI.\n */\nexport class CLIParam {\n\t/**\n\t * Check the option to see if it exists.\n\t * @param optionName The name of the option.\n\t * @param optionValue The option value.\n\t * @param allowEnvVar Allow the option to be read from an env var.\n\t * @returns The final option value.\n\t * @throws An error if the option is invalid.\n\t */\n\tpublic static env(\n\t\toptionName: string,\n\t\toptionValue: string | undefined,\n\t\tallowEnvVar: boolean\n\t): string | undefined {\n\t\tif (allowEnvVar && optionValue?.startsWith(\"!\")) {\n\t\t\tconst envValueName = optionValue.slice(1);\n\t\t\t// This is reading from an env var so it really has no choice\n\t\t\t// eslint-disable-next-line no-restricted-syntax\n\t\t\tconst envValue = process.env[envValueName];\n\t\t\tif (Is.empty(envValue)) {\n\t\t\t\tthrow new GeneralError(\"commands\", \"commands.common.missingEnv\", {\n\t\t\t\t\toption: optionName,\n\t\t\t\t\tvalue: envValueName\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\toptionValue = envValue;\n\t\t\t}\n\t\t}\n\t\treturn optionValue;\n\t}\n\n\t/**\n\t * Check the option to see if the String exists.\n\t * @param optionName The name of the option.\n\t * @param optionValue The option value.\n\t * @param allowEnvVar Allow the option to be read from an env var.\n\t * @returns The final option value.\n\t * @throws An error if the option is invalid.\n\t */\n\tpublic static stringValue(\n\t\toptionName: string,\n\t\toptionValue: string | undefined,\n\t\tallowEnvVar: boolean = true\n\t): string {\n\t\toptionValue = CLIParam.env(optionName, optionValue, allowEnvVar);\n\t\tGuards.stringValue(\"commands\", optionName, optionValue);\n\t\treturn optionValue;\n\t}\n\n\t/**\n\t * Check the option to see if the value exists in the specific array.\n\t * @param optionName The name of the option.\n\t * @param optionValue The option value.\n\t * @param validValues The valid values.\n\t * @param allowEnvVar Allow the option to be read from an env var.\n\t * @returns The final option value.\n\t * @throws An error if the option is invalid.\n\t */\n\tpublic static arrayOneOf<T = string>(\n\t\toptionName: string,\n\t\toptionValue: string | undefined,\n\t\tvalidValues: T[],\n\t\tallowEnvVar: boolean = true\n\t): T {\n\t\toptionValue = CLIParam.env(optionName, optionValue, allowEnvVar);\n\t\tGuards.arrayOneOf<T>(\"commands\", optionName, optionValue as T, validValues);\n\t\treturn optionValue as T;\n\t}\n\n\t/**\n\t * Check the option to see if it is a url.\n\t * @param optionName The name of the option.\n\t * @param optionValue The option value.\n\t * @param allowEnvVar Allow the option to be read from an env var.\n\t * @returns The final option value.\n\t * @throws An error if the option is invalid.\n\t */\n\tpublic static url(\n\t\toptionName: string,\n\t\toptionValue: string | undefined,\n\t\tallowEnvVar: boolean = true\n\t): string {\n\t\toptionValue = CLIParam.env(optionName, optionValue, allowEnvVar);\n\t\tUrl.guard(\"commands\", optionName, optionValue);\n\t\treturn optionValue;\n\t}\n\n\t/**\n\t * Check the option to see if it exists and is a number.\n\t * @param optionName The name of the option.\n\t * @param optionValue The option value.\n\t * @param allowEnvVar Allow the option to be read from an env var.\n\t * @param minValue The minimum value.\n\t * @param maxValue The maximum value.\n\t * @returns The final option value.\n\t * @throws An error if the option is invalid.\n\t */\n\tpublic static number(\n\t\toptionName: string,\n\t\toptionValue: string | undefined,\n\t\tallowEnvVar: boolean = true,\n\t\tminValue: number = 0,\n\t\tmaxValue?: number\n\t): number {\n\t\toptionValue = CLIParam.env(optionName, optionValue, allowEnvVar);\n\t\tconst coerced = Coerce.number(optionValue);\n\t\tif (Is.number(coerced)) {\n\t\t\tif (Is.number(minValue) && coerced < minValue) {\n\t\t\t\tthrow new GeneralError(\"commands\", \"commands.common.optionMinValue\", {\n\t\t\t\t\toption: optionName,\n\t\t\t\t\tvalue: optionValue,\n\t\t\t\t\tminValue\n\t\t\t\t});\n\t\t\t} else if (Is.number(maxValue) && coerced > maxValue) {\n\t\t\t\tthrow new GeneralError(\"commands\", \"commands.common.optionMaxValue\", {\n\t\t\t\t\toption: optionName,\n\t\t\t\t\tvalue: optionValue,\n\t\t\t\t\tmaxValue\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn coerced;\n\t\t}\n\t\tGuards.number(\"commands\", optionName, optionValue);\n\t\treturn 0;\n\t}\n\n\t/**\n\t * Check the option to see if it exists and is an integer.\n\t * @param optionName The name of the option.\n\t * @param optionValue The option value.\n\t * @param allowEnvVar Allow the option to be read from an env var.\n\t * @param minValue The minimum value.\n\t * @param maxValue The maximum value.\n\t * @returns The final option value.\n\t * @throws An error if the option is invalid.\n\t */\n\tpublic static integer(\n\t\toptionName: string,\n\t\toptionValue: string | undefined,\n\t\tallowEnvVar: boolean = true,\n\t\tminValue: number = 0,\n\t\tmaxValue?: number\n\t): number {\n\t\toptionValue = CLIParam.env(optionName, optionValue, allowEnvVar);\n\t\tconst coerced = Coerce.number(optionValue);\n\t\tif (Is.integer(coerced)) {\n\t\t\tif (Is.number(minValue) && coerced < minValue) {\n\t\t\t\tthrow new GeneralError(\"commands\", \"commands.common.optionMinValue\", {\n\t\t\t\t\toption: optionName,\n\t\t\t\t\tvalue: optionValue,\n\t\t\t\t\tminValue\n\t\t\t\t});\n\t\t\t} else if (Is.number(maxValue) && coerced > maxValue) {\n\t\t\t\tthrow new GeneralError(\"commands\", \"commands.common.optionMaxValue\", {\n\t\t\t\t\toption: optionName,\n\t\t\t\t\tvalue: optionValue,\n\t\t\t\t\tmaxValue\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn coerced;\n\t\t}\n\t\tGuards.integer(\"commands\", optionName, optionValue);\n\t\treturn 0;\n\t}\n\n\t/**\n\t * Check the option to see if it exists and is a big number.\n\t * @param optionName The name of the option.\n\t * @param optionValue The option value.\n\t * @param allowEnvVar Allow the option to be read from an env var.\n\t * @param minValue The minimum value.\n\t * @param maxValue The maximum value.\n\t * @returns The final option value.\n\t * @throws An error if the option is invalid.\n\t */\n\tpublic static bigint(\n\t\toptionName: string,\n\t\toptionValue: string | undefined,\n\t\tallowEnvVar: boolean = true,\n\t\tminValue: bigint = 0n,\n\t\tmaxValue?: bigint\n\t): bigint {\n\t\toptionValue = CLIParam.env(optionName, optionValue, allowEnvVar);\n\t\tconst coerced = Coerce.bigint(optionValue);\n\t\tif (Is.bigint(coerced)) {\n\t\t\tif (Is.bigint(minValue) && coerced < minValue) {\n\t\t\t\tthrow new GeneralError(\"commands\", \"commands.common.optionMinValue\", {\n\t\t\t\t\toption: optionName,\n\t\t\t\t\tvalue: optionValue,\n\t\t\t\t\tminValue\n\t\t\t\t});\n\t\t\t} else if (Is.bigint(maxValue) && coerced > maxValue) {\n\t\t\t\tthrow new GeneralError(\"commands\", \"commands.common.optionMaxValue\", {\n\t\t\t\t\toption: optionName,\n\t\t\t\t\tvalue: optionValue,\n\t\t\t\t\tmaxValue\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn coerced;\n\t\t}\n\t\tGuards.bigint(\"commands\", optionName, optionValue);\n\t\treturn 0n;\n\t}\n\n\t/**\n\t * Check the option to see if it exists and is a boolean.\n\t * @param optionName The name of the option.\n\t * @param optionValue The option value.\n\t * @param allowEnvVar Allow the option to be read from an env var.\n\t * @returns The final option value.\n\t * @throws An error if the option is invalid.\n\t */\n\tpublic static boolean(\n\t\toptionName: string,\n\t\toptionValue: string | undefined,\n\t\tallowEnvVar: boolean = true\n\t): boolean {\n\t\toptionValue = CLIParam.env(optionName, optionValue, allowEnvVar);\n\t\tconst coerced = Coerce.boolean(optionValue);\n\t\tif (Is.boolean(coerced)) {\n\t\t\treturn coerced;\n\t\t}\n\t\tGuards.boolean(\"commands\", optionName, optionValue);\n\t\treturn false;\n\t}\n\n\t/**\n\t * Check the option to see if it exists and is hex.\n\t * @param optionName The name of the option.\n\t * @param optionValue The option value.\n\t * @param allowEnvVar Allow the option to be read from an env var.\n\t * @returns The final option value.\n\t * @throws An error if the option is invalid.\n\t */\n\tpublic static hex(\n\t\toptionName: string,\n\t\toptionValue: string | undefined,\n\t\tallowEnvVar: boolean = true\n\t): Uint8Array {\n\t\toptionValue = CLIParam.env(optionName, optionValue, allowEnvVar);\n\n\t\tif (Is.stringHex(optionValue, true)) {\n\t\t\treturn Converter.hexToBytes(optionValue);\n\t\t}\n\t\tthrow new GeneralError(\"commands\", \"commands.common.optionInvalidHex\", {\n\t\t\toption: optionName,\n\t\t\tvalue: optionValue\n\t\t});\n\t}\n\n\t/**\n\t * Check the option to see if it exists and is base64.\n\t * @param optionName The name of the option.\n\t * @param optionValue The option value.\n\t * @param allowEnvVar Allow the option to be read from an env var.\n\t * @returns The final option value.\n\t * @throws An error if the option is invalid.\n\t */\n\tpublic static base64(\n\t\toptionName: string,\n\t\toptionValue: string | undefined,\n\t\tallowEnvVar: boolean = true\n\t): Uint8Array {\n\t\toptionValue = CLIParam.env(optionName, optionValue, allowEnvVar);\n\n\t\tif (Is.stringBase64(optionValue)) {\n\t\t\treturn Converter.base64ToBytes(optionValue);\n\t\t}\n\t\tthrow new GeneralError(\"commands\", \"commands.common.optionInvalidBase64\", {\n\t\t\toption: optionName,\n\t\t\tvalue: optionValue\n\t\t});\n\t}\n\n\t/**\n\t * Check the option to see if it exists and is hex or base64.\n\t * @param optionName The name of the option.\n\t * @param optionValue The option value.\n\t * @param allowEnvVar Allow the option to be read from an env var.\n\t * @returns The final option value.\n\t * @throws An error if the option is invalid.\n\t */\n\tpublic static hexBase64(\n\t\toptionName: string,\n\t\toptionValue: string | undefined,\n\t\tallowEnvVar: boolean = true\n\t): Uint8Array {\n\t\toptionValue = CLIParam.env(optionName, optionValue, allowEnvVar);\n\n\t\tif (Is.stringHex(optionValue, true)) {\n\t\t\treturn Converter.hexToBytes(optionValue);\n\t\t} else if (Is.stringBase64(optionValue)) {\n\t\t\treturn Converter.base64ToBytes(optionValue);\n\t\t}\n\t\tthrow new GeneralError(\"commands\", \"commands.common.optionInvalidHexBase64\", {\n\t\t\toption: optionName,\n\t\t\tvalue: optionValue\n\t\t});\n\t}\n}\n"]}
1
+ {"version":3,"file":"cliParam.js","sourceRoot":"","sources":["../../src/cliParam.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAElF;;GAEG;AACH,MAAM,OAAO,QAAQ;IACpB;;;;;;;OAOG;IACI,MAAM,CAAC,GAAG,CAChB,UAAkB,EAClB,WAA+B,EAC/B,WAAoB;QAEpB,IAAI,WAAW,IAAI,WAAW,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YACjD,MAAM,YAAY,GAAG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License-Identifier: Apache-2.0.\nimport { Coerce, Converter, GeneralError, Guards, Is, Url } from \"@twin.org/core\";\n\n/**\n * Parameter utilities for the CLI.\n */\nexport class CLIParam {\n\t/**\n\t * Check the option to see if it exists.\n\t * @param optionName The name of the option.\n\t * @param optionValue The option value.\n\t * @param allowEnvVar Allow the option to be read from an env var.\n\t * @returns The final option value.\n\t * @throws An error if the option is invalid.\n\t */\n\tpublic static env(\n\t\toptionName: string,\n\t\toptionValue: string | undefined,\n\t\tallowEnvVar: boolean\n\t): string | undefined {\n\t\tif (allowEnvVar && optionValue?.startsWith(\"!\")) {\n\t\t\tconst envValueName = optionValue.slice(1);\n\t\t\t// This is reading from an env var so it really has no choice\n\t\t\t// eslint-disable-next-line no-restricted-syntax\n\t\t\tconst envValue = process.env[envValueName];\n\t\t\tif (Is.empty(envValue)) {\n\t\t\t\tthrow new GeneralError(\"commands\", \"commands.common.missingEnv\", {\n\t\t\t\t\toption: optionName,\n\t\t\t\t\tvalue: envValueName\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\toptionValue = envValue;\n\t\t\t}\n\t\t}\n\t\treturn optionValue;\n\t}\n\n\t/**\n\t * Check the option to see if the String exists.\n\t * @param optionName The name of the option.\n\t * @param optionValue The option value.\n\t * @param allowEnvVar Allow the option to be read from an env var.\n\t * @returns The final option value.\n\t * @throws An error if the option is invalid.\n\t */\n\tpublic static stringValue(\n\t\toptionName: string,\n\t\toptionValue: string | undefined,\n\t\tallowEnvVar: boolean = true\n\t): string {\n\t\toptionValue = CLIParam.env(optionName, optionValue, allowEnvVar);\n\t\tGuards.stringValue(\"commands\", optionName, optionValue);\n\t\treturn optionValue;\n\t}\n\n\t/**\n\t * Check the option to see if the value exists in the specific array.\n\t * @param optionName The name of the option.\n\t * @param optionValue The option value.\n\t * @param validValues The valid values.\n\t * @param allowEnvVar Allow the option to be read from an env var.\n\t * @returns The final option value.\n\t * @throws An error if the option is invalid.\n\t */\n\tpublic static arrayOneOf<T = string>(\n\t\toptionName: string,\n\t\toptionValue: string | undefined,\n\t\tvalidValues: T[],\n\t\tallowEnvVar: boolean = true\n\t): T {\n\t\tconst stringValue = CLIParam.env(optionName, optionValue, allowEnvVar) as T;\n\t\tGuards.arrayOneOf<T>(\"commands\", optionName, stringValue, validValues);\n\t\treturn stringValue;\n\t}\n\n\t/**\n\t * Check the option to see if it is a url.\n\t * @param optionName The name of the option.\n\t * @param optionValue The option value.\n\t * @param allowEnvVar Allow the option to be read from an env var.\n\t * @returns The final option value.\n\t * @throws An error if the option is invalid.\n\t */\n\tpublic static url(\n\t\toptionName: string,\n\t\toptionValue: string | undefined,\n\t\tallowEnvVar: boolean = true\n\t): string {\n\t\toptionValue = CLIParam.env(optionName, optionValue, allowEnvVar);\n\t\tUrl.guard(\"commands\", optionName, optionValue);\n\t\treturn optionValue;\n\t}\n\n\t/**\n\t * Check the option to see if it exists and is a number.\n\t * @param optionName The name of the option.\n\t * @param optionValue The option value.\n\t * @param allowEnvVar Allow the option to be read from an env var.\n\t * @param minValue The minimum value.\n\t * @param maxValue The maximum value.\n\t * @returns The final option value.\n\t * @throws An error if the option is invalid.\n\t */\n\tpublic static number(\n\t\toptionName: string,\n\t\toptionValue: string | undefined,\n\t\tallowEnvVar: boolean = true,\n\t\tminValue: number = 0,\n\t\tmaxValue?: number\n\t): number {\n\t\toptionValue = CLIParam.env(optionName, optionValue, allowEnvVar);\n\t\tconst coerced = Coerce.number(optionValue);\n\t\tif (Is.number(coerced)) {\n\t\t\tif (Is.number(minValue) && coerced < minValue) {\n\t\t\t\tthrow new GeneralError(\"commands\", \"commands.common.optionMinValue\", {\n\t\t\t\t\toption: optionName,\n\t\t\t\t\tvalue: optionValue,\n\t\t\t\t\tminValue\n\t\t\t\t});\n\t\t\t} else if (Is.number(maxValue) && coerced > maxValue) {\n\t\t\t\tthrow new GeneralError(\"commands\", \"commands.common.optionMaxValue\", {\n\t\t\t\t\toption: optionName,\n\t\t\t\t\tvalue: optionValue,\n\t\t\t\t\tmaxValue\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn coerced;\n\t\t}\n\t\tGuards.number(\"commands\", optionName, optionValue);\n\t\treturn 0;\n\t}\n\n\t/**\n\t * Check the option to see if it exists and is an integer.\n\t * @param optionName The name of the option.\n\t * @param optionValue The option value.\n\t * @param allowEnvVar Allow the option to be read from an env var.\n\t * @param minValue The minimum value.\n\t * @param maxValue The maximum value.\n\t * @returns The final option value.\n\t * @throws An error if the option is invalid.\n\t */\n\tpublic static integer(\n\t\toptionName: string,\n\t\toptionValue: string | undefined,\n\t\tallowEnvVar: boolean = true,\n\t\tminValue: number = 0,\n\t\tmaxValue?: number\n\t): number {\n\t\toptionValue = CLIParam.env(optionName, optionValue, allowEnvVar);\n\t\tconst coerced = Coerce.number(optionValue);\n\t\tif (Is.integer(coerced)) {\n\t\t\tif (Is.number(minValue) && coerced < minValue) {\n\t\t\t\tthrow new GeneralError(\"commands\", \"commands.common.optionMinValue\", {\n\t\t\t\t\toption: optionName,\n\t\t\t\t\tvalue: optionValue,\n\t\t\t\t\tminValue\n\t\t\t\t});\n\t\t\t} else if (Is.number(maxValue) && coerced > maxValue) {\n\t\t\t\tthrow new GeneralError(\"commands\", \"commands.common.optionMaxValue\", {\n\t\t\t\t\toption: optionName,\n\t\t\t\t\tvalue: optionValue,\n\t\t\t\t\tmaxValue\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn coerced;\n\t\t}\n\t\tGuards.integer(\"commands\", optionName, optionValue);\n\t\treturn 0;\n\t}\n\n\t/**\n\t * Check the option to see if it exists and is a big number.\n\t * @param optionName The name of the option.\n\t * @param optionValue The option value.\n\t * @param allowEnvVar Allow the option to be read from an env var.\n\t * @param minValue The minimum value.\n\t * @param maxValue The maximum value.\n\t * @returns The final option value.\n\t * @throws An error if the option is invalid.\n\t */\n\tpublic static bigint(\n\t\toptionName: string,\n\t\toptionValue: string | undefined,\n\t\tallowEnvVar: boolean = true,\n\t\tminValue: bigint = 0n,\n\t\tmaxValue?: bigint\n\t): bigint {\n\t\toptionValue = CLIParam.env(optionName, optionValue, allowEnvVar);\n\t\tconst coerced = Coerce.bigint(optionValue);\n\t\tif (Is.bigint(coerced)) {\n\t\t\tif (Is.bigint(minValue) && coerced < minValue) {\n\t\t\t\tthrow new GeneralError(\"commands\", \"commands.common.optionMinValue\", {\n\t\t\t\t\toption: optionName,\n\t\t\t\t\tvalue: optionValue,\n\t\t\t\t\tminValue\n\t\t\t\t});\n\t\t\t} else if (Is.bigint(maxValue) && coerced > maxValue) {\n\t\t\t\tthrow new GeneralError(\"commands\", \"commands.common.optionMaxValue\", {\n\t\t\t\t\toption: optionName,\n\t\t\t\t\tvalue: optionValue,\n\t\t\t\t\tmaxValue\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn coerced;\n\t\t}\n\t\tGuards.bigint(\"commands\", optionName, optionValue);\n\t\treturn 0n;\n\t}\n\n\t/**\n\t * Check the option to see if it exists and is a boolean.\n\t * @param optionName The name of the option.\n\t * @param optionValue The option value.\n\t * @param allowEnvVar Allow the option to be read from an env var.\n\t * @returns The final option value.\n\t * @throws An error if the option is invalid.\n\t */\n\tpublic static boolean(\n\t\toptionName: string,\n\t\toptionValue: string | undefined,\n\t\tallowEnvVar: boolean = true\n\t): boolean {\n\t\toptionValue = CLIParam.env(optionName, optionValue, allowEnvVar);\n\t\tconst coerced = Coerce.boolean(optionValue);\n\t\tif (Is.boolean(coerced)) {\n\t\t\treturn coerced;\n\t\t}\n\t\tGuards.boolean(\"commands\", optionName, optionValue);\n\t\treturn false;\n\t}\n\n\t/**\n\t * Check the option to see if it exists and is hex.\n\t * @param optionName The name of the option.\n\t * @param optionValue The option value.\n\t * @param allowEnvVar Allow the option to be read from an env var.\n\t * @returns The final option value.\n\t * @throws An error if the option is invalid.\n\t */\n\tpublic static hex(\n\t\toptionName: string,\n\t\toptionValue: string | undefined,\n\t\tallowEnvVar: boolean = true\n\t): Uint8Array {\n\t\toptionValue = CLIParam.env(optionName, optionValue, allowEnvVar);\n\n\t\tif (Is.stringHex(optionValue, true)) {\n\t\t\treturn Converter.hexToBytes(optionValue);\n\t\t}\n\t\tthrow new GeneralError(\"commands\", \"commands.common.optionInvalidHex\", {\n\t\t\toption: optionName,\n\t\t\tvalue: optionValue\n\t\t});\n\t}\n\n\t/**\n\t * Check the option to see if it exists and is base64.\n\t * @param optionName The name of the option.\n\t * @param optionValue The option value.\n\t * @param allowEnvVar Allow the option to be read from an env var.\n\t * @returns The final option value.\n\t * @throws An error if the option is invalid.\n\t */\n\tpublic static base64(\n\t\toptionName: string,\n\t\toptionValue: string | undefined,\n\t\tallowEnvVar: boolean = true\n\t): Uint8Array {\n\t\toptionValue = CLIParam.env(optionName, optionValue, allowEnvVar);\n\n\t\tif (Is.stringBase64(optionValue)) {\n\t\t\treturn Converter.base64ToBytes(optionValue);\n\t\t}\n\t\tthrow new GeneralError(\"commands\", \"commands.common.optionInvalidBase64\", {\n\t\t\toption: optionName,\n\t\t\tvalue: optionValue\n\t\t});\n\t}\n\n\t/**\n\t * Check the option to see if it exists and is hex or base64.\n\t * @param optionName The name of the option.\n\t * @param optionValue The option value.\n\t * @param allowEnvVar Allow the option to be read from an env var.\n\t * @returns The final option value.\n\t * @throws An error if the option is invalid.\n\t */\n\tpublic static hexBase64(\n\t\toptionName: string,\n\t\toptionValue: string | undefined,\n\t\tallowEnvVar: boolean = true\n\t): Uint8Array {\n\t\toptionValue = CLIParam.env(optionName, optionValue, allowEnvVar);\n\n\t\tif (Is.stringHex(optionValue, true)) {\n\t\t\treturn Converter.hexToBytes(optionValue);\n\t\t} else if (Is.stringBase64(optionValue)) {\n\t\t\treturn Converter.base64ToBytes(optionValue);\n\t\t}\n\t\tthrow new GeneralError(\"commands\", \"commands.common.optionInvalidHexBase64\", {\n\t\t\toption: optionName,\n\t\t\tvalue: optionValue\n\t\t});\n\t}\n}\n"]}
package/docs/changelog.md CHANGED
@@ -1,5 +1,42 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.0.3-next.39](https://github.com/iotaledger/twin-framework/compare/cli-core-v0.0.3-next.38...cli-core-v0.0.3-next.39) (2026-05-13)
4
+
5
+
6
+ ### Features
7
+
8
+ * improve signatures ([bcc21ae](https://github.com/iotaledger/twin-framework/commit/bcc21aed3e10a264ef5c8515bde8dcac8a05c719))
9
+ * improve signatures ([cdd24be](https://github.com/iotaledger/twin-framework/commit/cdd24be6fb898d33955b6f2f93c3ddbd73582269))
10
+
11
+
12
+ ### Dependencies
13
+
14
+ * The following workspace dependencies were updated
15
+ * dependencies
16
+ * @twin.org/core bumped from 0.0.3-next.38 to 0.0.3-next.39
17
+ * @twin.org/nameof bumped from 0.0.3-next.38 to 0.0.3-next.39
18
+ * devDependencies
19
+ * @twin.org/nameof-transformer bumped from 0.0.3-next.38 to 0.0.3-next.39
20
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.3-next.38 to 0.0.3-next.39
21
+
22
+ ## [0.0.3-next.38](https://github.com/iotaledger/twin-framework/compare/cli-core-v0.0.3-next.37...cli-core-v0.0.3-next.38) (2026-05-11)
23
+
24
+
25
+ ### Features
26
+
27
+ * typescript 6 update ([1d10f31](https://github.com/iotaledger/twin-framework/commit/1d10f31e6516ec622773f45e88af82fe749b384a))
28
+
29
+
30
+ ### Dependencies
31
+
32
+ * The following workspace dependencies were updated
33
+ * dependencies
34
+ * @twin.org/core bumped from 0.0.3-next.37 to 0.0.3-next.38
35
+ * @twin.org/nameof bumped from 0.0.3-next.37 to 0.0.3-next.38
36
+ * devDependencies
37
+ * @twin.org/nameof-transformer bumped from 0.0.3-next.37 to 0.0.3-next.38
38
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.3-next.37 to 0.0.3-next.38
39
+
3
40
  ## [0.0.3-next.37](https://github.com/iotaledger/twin-framework/compare/cli-core-v0.0.3-next.36...cli-core-v0.0.3-next.37) (2026-05-07)
4
41
 
5
42
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/cli-core",
3
- "version": "0.0.3-next.37",
3
+ "version": "0.0.3-next.39",
4
4
  "description": "Core classes for building a CLI",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,11 +14,11 @@
14
14
  "node": ">=20.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "@twin.org/core": "0.0.3-next.37",
18
- "@twin.org/nameof": "0.0.3-next.37",
17
+ "@twin.org/core": "0.0.3-next.39",
18
+ "@twin.org/nameof": "0.0.3-next.39",
19
19
  "chalk": "5.6.2",
20
20
  "commander": "14.0.3",
21
- "dotenv": "17.3.1"
21
+ "dotenv": "17.4.2"
22
22
  },
23
23
  "main": "./dist/es/index.js",
24
24
  "types": "./dist/types/index.d.ts",