@twin.org/cli-core 0.0.3-next.4 → 0.0.3-next.41

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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # TWIN CLI Core
2
2
 
3
- Core classes for building a CLI.
3
+ This package is part of the framework workspace and provides core classes for building a CLI to support consistent development workflows across the ecosystem.
4
4
 
5
5
  ## Installation
6
6
 
@@ -10,7 +10,7 @@ npm install @twin.org/cli-core
10
10
 
11
11
  ## Examples
12
12
 
13
- Usage of the tool is shown in the examples [docs/examples.md](docs/examples.md)
13
+ Usage of the APIs is shown in the examples [docs/examples.md](docs/examples.md)
14
14
 
15
15
  ## Reference
16
16
 
@@ -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,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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\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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W,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\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"]}