@iobroker/js-controller-cli 7.2.3 → 8.0.0-alpha.1-20260921-e5941ca8a
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/build/cjs/index.js +3 -3
- package/build/cjs/lib/_Types.d.ts +8 -1
- package/build/cjs/lib/cli/cliCert.d.ts +7 -4
- package/build/cjs/lib/cli/cliCert.js +10 -6
- package/build/cjs/lib/cli/cliCert.js.map +2 -2
- package/build/cjs/lib/cli/cliCommand.d.ts +63 -15
- package/build/cjs/lib/cli/cliCommand.js +8 -1
- package/build/cjs/lib/cli/cliCommand.js.map +2 -2
- package/build/cjs/lib/cli/cliCompact.d.ts +5 -2
- package/build/cjs/lib/cli/cliCompact.js +9 -2
- package/build/cjs/lib/cli/cliCompact.js.map +2 -2
- package/build/cjs/lib/cli/cliDebug.d.ts +5 -2
- package/build/cjs/lib/cli/cliDebug.js +8 -1
- package/build/cjs/lib/cli/cliDebug.js.map +2 -2
- package/build/cjs/lib/cli/cliHost.d.ts +13 -10
- package/build/cjs/lib/cli/cliHost.js +13 -5
- package/build/cjs/lib/cli/cliHost.js.map +2 -2
- package/build/cjs/lib/cli/cliLogs.d.ts +9 -3
- package/build/cjs/lib/cli/cliLogs.js +12 -1
- package/build/cjs/lib/cli/cliLogs.js.map +2 -2
- package/build/cjs/lib/cli/cliMessage.d.ts +2 -1
- package/build/cjs/lib/cli/cliMessage.js +5 -0
- package/build/cjs/lib/cli/cliMessage.js.map +2 -2
- package/build/cjs/lib/cli/cliObjects.d.ts +21 -18
- package/build/cjs/lib/cli/cliObjects.js +51 -33
- package/build/cjs/lib/cli/cliObjects.js.map +2 -2
- package/build/cjs/lib/cli/cliPlugin.d.ts +3 -3
- package/build/cjs/lib/cli/cliPlugin.js +6 -0
- package/build/cjs/lib/cli/cliPlugin.js.map +2 -2
- package/build/cjs/lib/cli/cliProcess.d.ts +17 -7
- package/build/cjs/lib/cli/cliProcess.js +77 -24
- package/build/cjs/lib/cli/cliProcess.js.map +3 -3
- package/build/cjs/lib/cli/cliStates.d.ts +7 -4
- package/build/cjs/lib/cli/cliStates.js +14 -6
- package/build/cjs/lib/cli/cliStates.js.map +2 -2
- package/build/cjs/lib/cli/cliTools.js +11 -0
- package/build/cjs/lib/cli/cliTools.js.map +1 -1
- package/build/cjs/lib/cli/messages.js +47 -46
- package/build/cjs/lib/cli/messages.js.map +1 -1
- package/build/cjs/lib/progressBar.d.ts +59 -0
- package/build/cjs/lib/progressBar.js +115 -0
- package/build/cjs/lib/progressBar.js.map +7 -0
- package/build/cjs/lib/setup/customError.d.ts +4 -0
- package/build/cjs/lib/setup/customError.js +7 -0
- package/build/cjs/lib/setup/customError.js.map +2 -2
- package/build/cjs/lib/setup/dbConnection.js +69 -64
- package/build/cjs/lib/setup/dbConnection.js.map +3 -3
- package/build/cjs/lib/setup/formatters.d.ts +4 -4
- package/build/cjs/lib/setup/formatters.js +5 -0
- package/build/cjs/lib/setup/formatters.js.map +2 -2
- package/build/cjs/lib/setup/multihostClient.js +6 -2
- package/build/cjs/lib/setup/multihostClient.js.map +1 -1
- package/build/cjs/lib/setup/pluginInfos.d.ts +5 -0
- package/build/cjs/lib/setup/pluginInfos.js +2 -0
- package/build/cjs/lib/setup/pluginInfos.js.map +2 -2
- package/build/cjs/lib/setup/setupBackup.d.ts +53 -0
- package/build/cjs/lib/setup/setupBackup.js +125 -14
- package/build/cjs/lib/setup/setupBackup.js.map +3 -3
- package/build/cjs/lib/setup/setupInstall.d.ts +51 -15
- package/build/cjs/lib/setup/setupInstall.js +212 -28
- package/build/cjs/lib/setup/setupInstall.js.map +2 -2
- package/build/cjs/lib/setup/setupLicense.d.ts +13 -0
- package/build/cjs/lib/setup/setupLicense.js +33 -2
- package/build/cjs/lib/setup/setupLicense.js.map +2 -2
- package/build/cjs/lib/setup/setupList.d.ts +55 -1
- package/build/cjs/lib/setup/setupList.js +78 -24
- package/build/cjs/lib/setup/setupList.js.map +3 -3
- package/build/cjs/lib/setup/setupMultihost.d.ts +7 -0
- package/build/cjs/lib/setup/setupMultihost.js +78 -11
- package/build/cjs/lib/setup/setupMultihost.js.map +3 -3
- package/build/cjs/lib/setup/setupPacketManager.d.ts +10 -0
- package/build/cjs/lib/setup/setupPacketManager.js +16 -6
- package/build/cjs/lib/setup/setupPacketManager.js.map +2 -2
- package/build/cjs/lib/setup/setupRepo.d.ts +19 -0
- package/build/cjs/lib/setup/setupRepo.js +141 -13
- package/build/cjs/lib/setup/setupRepo.js.map +2 -2
- package/build/cjs/lib/setup/setupSetup.d.ts +34 -0
- package/build/cjs/lib/setup/setupSetup.js +209 -35
- package/build/cjs/lib/setup/setupSetup.js.map +3 -3
- package/build/cjs/lib/setup/setupUpgrade.d.ts +13 -2
- package/build/cjs/lib/setup/setupUpgrade.js +72 -12
- package/build/cjs/lib/setup/setupUpgrade.js.map +2 -2
- package/build/cjs/lib/setup/setupUpload.d.ts +77 -1
- package/build/cjs/lib/setup/setupUpload.js +152 -9
- package/build/cjs/lib/setup/setupUpload.js.map +2 -2
- package/build/cjs/lib/setup/setupUsers.d.ts +44 -14
- package/build/cjs/lib/setup/setupUsers.js +330 -17
- package/build/cjs/lib/setup/setupUsers.js.map +2 -2
- package/build/cjs/lib/setup/setupVendor.d.ts +14 -1
- package/build/cjs/lib/setup/setupVendor.js +40 -8
- package/build/cjs/lib/setup/setupVendor.js.map +2 -2
- package/build/cjs/lib/setup/setupVisDebug.d.ts +16 -2
- package/build/cjs/lib/setup/setupVisDebug.js +41 -17
- package/build/cjs/lib/setup/setupVisDebug.js.map +3 -3
- package/build/cjs/lib/setup/utils.d.ts +1 -1
- package/build/cjs/lib/setup/utils.js +13 -9
- package/build/cjs/lib/setup/utils.js.map +3 -3
- package/build/cjs/lib/setup.d.ts +1 -1
- package/build/cjs/lib/setup.js +858 -1758
- package/build/cjs/lib/setup.js.map +3 -3
- package/build/esm/lib/_Types.d.ts +8 -1
- package/build/esm/lib/_Types.d.ts.map +1 -1
- package/build/esm/lib/cli/cliCert.d.ts +7 -4
- package/build/esm/lib/cli/cliCert.d.ts.map +1 -1
- package/build/esm/lib/cli/cliCert.js +6 -6
- package/build/esm/lib/cli/cliCert.js.map +1 -1
- package/build/esm/lib/cli/cliCommand.d.ts +63 -15
- package/build/esm/lib/cli/cliCommand.d.ts.map +1 -1
- package/build/esm/lib/cli/cliCommand.js +4 -1
- package/build/esm/lib/cli/cliCommand.js.map +1 -1
- package/build/esm/lib/cli/cliCompact.d.ts +5 -2
- package/build/esm/lib/cli/cliCompact.d.ts.map +1 -1
- package/build/esm/lib/cli/cliCompact.js +5 -2
- package/build/esm/lib/cli/cliCompact.js.map +1 -1
- package/build/esm/lib/cli/cliDebug.d.ts +5 -2
- package/build/esm/lib/cli/cliDebug.d.ts.map +1 -1
- package/build/esm/lib/cli/cliDebug.js +4 -1
- package/build/esm/lib/cli/cliDebug.js.map +1 -1
- package/build/esm/lib/cli/cliHost.d.ts +13 -10
- package/build/esm/lib/cli/cliHost.d.ts.map +1 -1
- package/build/esm/lib/cli/cliHost.js +8 -5
- package/build/esm/lib/cli/cliHost.js.map +1 -1
- package/build/esm/lib/cli/cliLogs.d.ts +9 -3
- package/build/esm/lib/cli/cliLogs.d.ts.map +1 -1
- package/build/esm/lib/cli/cliLogs.js +8 -1
- package/build/esm/lib/cli/cliLogs.js.map +1 -1
- package/build/esm/lib/cli/cliMessage.d.ts +2 -1
- package/build/esm/lib/cli/cliMessage.d.ts.map +1 -1
- package/build/esm/lib/cli/cliMessage.js +1 -0
- package/build/esm/lib/cli/cliMessage.js.map +1 -1
- package/build/esm/lib/cli/cliObjects.d.ts +21 -18
- package/build/esm/lib/cli/cliObjects.d.ts.map +1 -1
- package/build/esm/lib/cli/cliObjects.js +44 -38
- package/build/esm/lib/cli/cliObjects.js.map +1 -1
- package/build/esm/lib/cli/cliPlugin.d.ts +3 -3
- package/build/esm/lib/cli/cliPlugin.d.ts.map +1 -1
- package/build/esm/lib/cli/cliPlugin.js +1 -1
- package/build/esm/lib/cli/cliPlugin.js.map +1 -1
- package/build/esm/lib/cli/cliProcess.d.ts +17 -7
- package/build/esm/lib/cli/cliProcess.d.ts.map +1 -1
- package/build/esm/lib/cli/cliProcess.js +73 -12
- package/build/esm/lib/cli/cliProcess.js.map +1 -1
- package/build/esm/lib/cli/cliStates.d.ts +7 -4
- package/build/esm/lib/cli/cliStates.d.ts.map +1 -1
- package/build/esm/lib/cli/cliStates.js +6 -2
- package/build/esm/lib/cli/cliStates.js.map +1 -1
- package/build/esm/lib/progressBar.d.ts +59 -0
- package/build/esm/lib/progressBar.d.ts.map +1 -0
- package/build/esm/lib/progressBar.js +104 -0
- package/build/esm/lib/progressBar.js.map +1 -0
- package/build/esm/lib/setup/customError.d.ts +4 -0
- package/build/esm/lib/setup/customError.d.ts.map +1 -1
- package/build/esm/lib/setup/customError.js +3 -0
- package/build/esm/lib/setup/customError.js.map +1 -1
- package/build/esm/lib/setup/dbConnection.d.ts.map +1 -1
- package/build/esm/lib/setup/dbConnection.js +10 -13
- package/build/esm/lib/setup/dbConnection.js.map +1 -1
- package/build/esm/lib/setup/formatters.d.ts +4 -4
- package/build/esm/lib/setup/formatters.js +4 -4
- package/build/esm/lib/setup/pluginInfos.d.ts +5 -0
- package/build/esm/lib/setup/pluginInfos.d.ts.map +1 -1
- package/build/esm/lib/setup/pluginInfos.js +5 -0
- package/build/esm/lib/setup/pluginInfos.js.map +1 -1
- package/build/esm/lib/setup/setupBackup.d.ts +53 -0
- package/build/esm/lib/setup/setupBackup.d.ts.map +1 -1
- package/build/esm/lib/setup/setupBackup.js +132 -13
- package/build/esm/lib/setup/setupBackup.js.map +1 -1
- package/build/esm/lib/setup/setupInstall.d.ts +51 -15
- package/build/esm/lib/setup/setupInstall.d.ts.map +1 -1
- package/build/esm/lib/setup/setupInstall.js +228 -23
- package/build/esm/lib/setup/setupInstall.js.map +1 -1
- package/build/esm/lib/setup/setupLicense.d.ts +13 -0
- package/build/esm/lib/setup/setupLicense.d.ts.map +1 -1
- package/build/esm/lib/setup/setupLicense.js +31 -1
- package/build/esm/lib/setup/setupLicense.js.map +1 -1
- package/build/esm/lib/setup/setupList.d.ts +55 -1
- package/build/esm/lib/setup/setupList.d.ts.map +1 -1
- package/build/esm/lib/setup/setupList.js +61 -8
- package/build/esm/lib/setup/setupList.js.map +1 -1
- package/build/esm/lib/setup/setupMultihost.d.ts +7 -0
- package/build/esm/lib/setup/setupMultihost.d.ts.map +1 -1
- package/build/esm/lib/setup/setupMultihost.js +85 -6
- package/build/esm/lib/setup/setupMultihost.js.map +1 -1
- package/build/esm/lib/setup/setupPacketManager.d.ts +10 -0
- package/build/esm/lib/setup/setupPacketManager.d.ts.map +1 -1
- package/build/esm/lib/setup/setupPacketManager.js +9 -0
- package/build/esm/lib/setup/setupPacketManager.js.map +1 -1
- package/build/esm/lib/setup/setupRepo.d.ts +19 -0
- package/build/esm/lib/setup/setupRepo.d.ts.map +1 -1
- package/build/esm/lib/setup/setupRepo.js +164 -14
- package/build/esm/lib/setup/setupRepo.js.map +1 -1
- package/build/esm/lib/setup/setupSetup.d.ts +34 -0
- package/build/esm/lib/setup/setupSetup.d.ts.map +1 -1
- package/build/esm/lib/setup/setupSetup.js +218 -21
- package/build/esm/lib/setup/setupSetup.js.map +1 -1
- package/build/esm/lib/setup/setupUpgrade.d.ts +13 -2
- package/build/esm/lib/setup/setupUpgrade.d.ts.map +1 -1
- package/build/esm/lib/setup/setupUpgrade.js +70 -6
- package/build/esm/lib/setup/setupUpgrade.js.map +1 -1
- package/build/esm/lib/setup/setupUpload.d.ts +77 -1
- package/build/esm/lib/setup/setupUpload.d.ts.map +1 -1
- package/build/esm/lib/setup/setupUpload.js +164 -7
- package/build/esm/lib/setup/setupUpload.js.map +1 -1
- package/build/esm/lib/setup/setupUsers.d.ts +44 -14
- package/build/esm/lib/setup/setupUsers.d.ts.map +1 -1
- package/build/esm/lib/setup/setupUsers.js +346 -14
- package/build/esm/lib/setup/setupUsers.js.map +1 -1
- package/build/esm/lib/setup/setupVendor.d.ts +14 -1
- package/build/esm/lib/setup/setupVendor.d.ts.map +1 -1
- package/build/esm/lib/setup/setupVendor.js +33 -2
- package/build/esm/lib/setup/setupVendor.js.map +1 -1
- package/build/esm/lib/setup/setupVisDebug.d.ts +16 -2
- package/build/esm/lib/setup/setupVisDebug.d.ts.map +1 -1
- package/build/esm/lib/setup/setupVisDebug.js +39 -14
- package/build/esm/lib/setup/setupVisDebug.js.map +1 -1
- package/build/esm/lib/setup/utils.d.ts +1 -1
- package/build/esm/lib/setup/utils.d.ts.map +1 -1
- package/build/esm/lib/setup/utils.js +2 -4
- package/build/esm/lib/setup/utils.js.map +1 -1
- package/build/esm/lib/setup.d.ts +1 -1
- package/build/esm/lib/setup.d.ts.map +1 -1
- package/build/esm/lib/setup.js +959 -1910
- package/build/esm/lib/setup.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +14 -14
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/cli/cliStates.ts"],
|
|
4
|
-
"sourcesContent": ["import { tools } from '@iobroker/js-controller-common';\nimport { CLICommand, type CLICommandOptions } from './cliCommand.js';\nimport type { Client as ObjectsClient } from '@iobroker/db-objects-redis';\nimport * as CLI from '@/lib/cli/messages.js';\nimport { formatValue } from '@/lib/cli/cliTools.js';\nimport * as rl from 'readline-sync';\n\nconst ALIAS_STARTS_WITH = 'alias.';\n\ntype ResultTransform = (input: ioBroker.State) => string;\n\ninterface CLIStatesOptions extends CLICommandOptions {\n id?: string;\n value?: string | boolean | number;\n ack?: 'true' | 'false' | 0 | 1;\n}\n\n/** Command iobroker state ... */\nexport class CLIStates extends CLICommand<CLIStatesOptions> {\n constructor(options: CLIStatesOptions) {\n super(options);\n }\n\n /**\n * Executes a command\n *\n * @param args parsed cli args\n */\n execute(args: any[]): void {\n const { callback, pretty, showHelp } = this.options;\n const command = args[0];\n let resultTransform: ResultTransform;\n\n switch (command) {\n case 'get':\n resultTransform = obj => formatValue(obj, pretty);\n return this.get_(args, resultTransform);\n case 'getPlain':\n case 'getplain':\n resultTransform = obj => {\n if (!obj) {\n return 'null';\n }\n\n return [obj.val, obj.ack, obj.from, obj.ts, obj.lc].map(line => formatValue(line)).join('\\n');\n };\n return this.get_(args, resultTransform);\n case 'getValue':\n case 'getvalue':\n resultTransform = obj => (obj ? formatValue(obj.val, pretty) : 'null');\n return this.get_(args, resultTransform);\n case 'set':\n return this.set_(args);\n case 'chmod':\n case 'chown':\n CLI.error.wrongCommandPrefix('state', command, 'object');\n return void callback(3);\n case 'delete':\n case 'del':\n return this.delete(args);\n case 'getDBVersion':\n return this.getDBVersion();\n case 'setDBVersion':\n return this.setDBVersion();\n default:\n CLI.error.unknownCommand('state', command);\n showHelp();\n return void callback(3);\n }\n }\n\n /**\n * Get the protocol version\n */\n getDBVersion(): void {\n const { callback, dbConnect } = this.options;\n dbConnect(async params => {\n const { states } = params;\n const version = await states.getProtocolVersion();\n console.log(`Current States DB protocol version: ${version}`);\n return void callback(0);\n });\n }\n\n /**\n * Set protocol version\n */\n setDBVersion(): void {\n const { callback, dbConnect } = this.options;\n dbConnect(async params => {\n const { states } = params;\n\n let answer = rl.question('Changing the protocol version will restart all hosts! Continue? [N/y]', {\n limit: /^(yes|y|n|no)$/i,\n defaultInput: 'no',\n });\n\n answer = answer.toLowerCase();\n\n if (answer !== 'y' && answer !== 'yes') {\n console.log('Protocol version has not been changed!');\n return void callback(0);\n }\n\n try {\n await states.setProtocolVersion(this.options.version);\n } catch (e) {\n console.error(`Cannot update protocol version: ${e.message}`);\n return void callback(1);\n }\n console.log(`States DB protocol updated to version ${this.options.version}`);\n return void callback(0);\n });\n }\n\n /**\n * Checks if state is a binary state\n *\n * @param id id of the state\n * @param objects the objects db\n * @param _obj cached object\n */\n private async _isBinary(id: string, objects: ObjectsClient, _obj?: ioBroker.AnyObject | null): Promise<boolean> {\n const obj = _obj || (await objects.getObject(id));\n\n return !!(obj && ('binary' in obj || (obj.common && 'type' in obj.common && obj.common.type === 'file')));\n }\n\n /**\n * Returns the value of a state\n *\n * @param args parsed cli arguments\n * @param resultTransform transform function for result\n */\n get_(args: any[], resultTransform: ResultTransform): void {\n const { callback, dbConnect } = this.options;\n const id = args[1];\n\n if (!id) {\n CLI.error.stateNotFound(id);\n return;\n }\n\n dbConnect(async params => {\n const { states, objects } = params;\n\n if (id.startsWith(ALIAS_STARTS_WITH)) {\n objects.getObject(id, (err, targetObj) => {\n // alias\n if (targetObj && targetObj.common && 'alias' in targetObj.common && targetObj.common.alias.id) {\n const aliasId =\n typeof targetObj.common.alias.id.read === 'string'\n ? targetObj.common.alias.id.read\n : targetObj.common.alias.id;\n objects.getObject(aliasId, async (_err, sourceObj) => {\n // read target\n try {\n if (await this._isBinary(aliasId, objects, targetObj)) {\n CLI.error.stateBinaryGetUnsupported(aliasId);\n return void callback(1);\n }\n\n const state = await states.getStateAsync(aliasId);\n if (!state) {\n CLI.error.stateNotFound(id);\n } else {\n tools.formatAliasValue({\n sourceCommon: sourceObj?.common as ioBroker.StateCommon | undefined,\n targetCommon: targetObj.common as ioBroker.StateCommon,\n state,\n logger: console,\n logNamespace: '',\n sourceId: sourceObj?._id,\n targetId: targetObj._id,\n });\n console.log(resultTransform(state));\n }\n } catch (e) {\n CLI.error.unknown(e);\n }\n return void callback(0);\n });\n } else {\n CLI.error.unknown(err?.message || `Alias ${id} has no target`);\n return void callback(1); // ?\n }\n });\n } else {\n try {\n if (await this._isBinary(id, objects)) {\n CLI.error.stateBinaryGetUnsupported(id);\n return void callback(1);\n }\n const state = await states.getStateAsync(id);\n if (!state) {\n CLI.error.stateNotFound(id);\n } else {\n console.log(resultTransform(state));\n }\n } catch (e) {\n CLI.error.unknown(e);\n }\n return void callback(0);\n }\n });\n }\n\n /**\n * Set state in database\n *\n * @param args parsed cli arguments\n */\n set_(args: any[]): void {\n const { callback, dbConnect, showHelp, value, ack: ackArg, id } = this.options;\n const force = args.includes('--force') || args.includes('-f');\n\n if (id === undefined) {\n CLI.error.requiredArgumentMissing('id');\n showHelp();\n return void callback(0);\n }\n\n if (value === undefined) {\n CLI.error.requiredArgumentMissing('value');\n showHelp();\n return void callback(0);\n }\n\n let ack = false;\n\n if (ackArg !== undefined) {\n ack = ackArg === 'true' || ackArg === 1;\n }\n\n dbConnect(params => {\n const { states, objects } = params;\n const newVal = { val: value, ack: !!ack };\n\n if (id.startsWith(ALIAS_STARTS_WITH)) {\n objects.getObject(id, async (_err, obj) => {\n if (await this._isBinary(id, objects, obj)) {\n CLI.error.stateBinarySetUnsupported(id);\n return void callback(1);\n }\n // alias\n if (obj?.common?.alias?.id) {\n const aliasId =\n typeof obj.common.alias.id.write === 'string'\n ? obj.common.alias.id.write\n : obj.common.alias.id;\n\n objects.getObject(aliasId, (err, targetObj) => {\n if (err) {\n CLI.error.unknown(err.message);\n return void callback(1); // access error\n }\n if (!obj && !force) {\n CLI.error.objectNotFound(id, 'null');\n return void callback(1); // object not exists\n }\n\n if (obj?.common?.type) {\n if (obj.common.type === 'string') {\n newVal.val = newVal.val.toString();\n } else if (obj.common.type === 'number') {\n newVal.val = Number(newVal.val);\n } else if (obj.common.type === 'boolean') {\n newVal.val = newVal.val.toString();\n newVal.val =\n newVal.val === 'true' ||\n newVal.val === '1' ||\n newVal.val === 'ON' ||\n newVal.val === 'on';\n }\n }\n\n // write target\n states.setState(\n aliasId,\n tools.formatAliasValue({\n sourceCommon: obj.common as ioBroker.StateCommon,\n targetCommon: targetObj?.common as ioBroker.StateCommon | undefined,\n state: newVal as ioBroker.State,\n logger: console,\n logNamespace: '',\n sourceId: obj._id,\n targetId: targetObj?._id,\n }),\n err => {\n if (err) {\n CLI.error.unknown(err.message);\n return void callback(1); // ?\n }\n CLI.success.stateUpdated(id, value, !!ack);\n return void callback(0);\n },\n );\n });\n } else {\n CLI.error.unknown(`Alias ${id} has no target`);\n return void callback(1); // ?\n }\n });\n } else {\n objects.getObject(id, async (err, obj) => {\n if (err) {\n CLI.error.unknown(err.message);\n return void callback(1); // access error\n }\n\n if (await this._isBinary(id, objects, obj)) {\n CLI.error.stateBinarySetUnsupported(id);\n return void callback(1);\n }\n\n if (!obj && !force) {\n CLI.error.objectNotFound(id, 'null');\n return void callback(1); // object not exists\n }\n\n if (obj?.common?.type) {\n if (obj.common.type === 'string') {\n newVal.val = newVal.val.toString();\n } else if (obj.common.type === 'number') {\n newVal.val = Number(newVal.val);\n } else if (obj.common.type === 'boolean') {\n newVal.val = newVal.val.toString();\n newVal.val =\n newVal.val === 'true' ||\n newVal.val === '1' ||\n newVal.val === 'ON' ||\n newVal.val === 'on';\n }\n }\n\n states.setState(id, newVal, err => {\n if (err) {\n CLI.error.unknown(err.message);\n return void callback(1); // ?\n }\n CLI.success.stateUpdated(id, value, !!ack);\n return void callback(0);\n });\n });\n }\n });\n }\n\n /**\n * Deletes a state\n *\n * @param args parsed cli arguments\n */\n delete(args: any[]): void {\n const { callback, dbConnect } = this.options;\n const id: string = args[1];\n if (!id) {\n CLI.error.requiredArgumentMissing('id', 'state delete id');\n return void callback(1);\n }\n\n dbConnect(params => {\n const { states } = params;\n\n states.delState(id, err => {\n if (err) {\n CLI.error.stateNotFound(id, err.message);\n return void callback(3);\n }\n CLI.success.stateDeleted(id);\n return void callback(0);\n });\n });\n }\n}\n"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { tools } from '@iobroker/js-controller-common';\nimport { CLICommand, type CLICommandOptions } from './cliCommand.js';\nimport type { Client as ObjectsClient } from '@iobroker/db-objects-redis';\nimport * as CLI from '@/lib/cli/messages.js';\nimport { formatValue } from '@/lib/cli/cliTools.js';\nimport * as rl from 'readline-sync';\nimport { getLogger } from '@iobroker/js-controller-common-db/tools';\n\nconst ALIAS_STARTS_WITH = 'alias.';\n\ntype ResultTransform = (input: ioBroker.State) => string;\n\ninterface CLIStatesOptions extends CLICommandOptions {\n id?: string;\n value?: string | boolean | number;\n ack?: 'true' | 'false' | 0 | 1;\n}\n\n/** Command iobroker state ... */\nexport class CLIStates extends CLICommand<CLIStatesOptions> {\n /**\n * @param options The command options including context and parameters\n */\n constructor(options: CLIStatesOptions) {\n super(options);\n }\n\n /**\n * Executes a command\n *\n * @param args parsed cli args\n */\n execute(args: string[]): void {\n const { callback, pretty, showHelp } = this.options;\n const command = args[0];\n let resultTransform: ResultTransform;\n\n switch (command) {\n case 'get':\n resultTransform = obj => formatValue(obj, pretty);\n return this.get_(args, resultTransform);\n case 'getPlain':\n case 'getplain':\n resultTransform = obj => {\n if (!obj) {\n return 'null';\n }\n\n return [obj.val, obj.ack, obj.from, obj.ts, obj.lc].map(line => formatValue(line)).join('\\n');\n };\n return this.get_(args, resultTransform);\n case 'getValue':\n case 'getvalue':\n resultTransform = obj => (obj ? formatValue(obj.val, pretty) : 'null');\n return this.get_(args, resultTransform);\n case 'set':\n return this.set_(args);\n case 'chmod':\n case 'chown':\n CLI.error.wrongCommandPrefix('state', command, 'object');\n return void callback(3);\n case 'delete':\n case 'del':\n return this.delete(args);\n case 'getDBVersion':\n return this.getDBVersion();\n case 'setDBVersion':\n return this.setDBVersion();\n default:\n CLI.error.unknownCommand('state', command);\n showHelp();\n return void callback(3);\n }\n }\n\n /**\n * Get the protocol version\n */\n getDBVersion(): void {\n const { callback, dbConnect } = this.options;\n dbConnect(async params => {\n const { states } = params;\n const version = await states.getProtocolVersion();\n console.log(`Current States DB protocol version: ${version}`);\n return void callback(0);\n });\n }\n\n /**\n * Set protocol version\n */\n setDBVersion(): void {\n const { callback, dbConnect } = this.options;\n dbConnect(async params => {\n const { states } = params;\n\n let answer = rl.question('Changing the protocol version will restart all hosts! Continue? [N/y]', {\n limit: /^(yes|y|n|no)$/i,\n defaultInput: 'no',\n });\n\n answer = answer.toLowerCase();\n\n if (answer !== 'y' && answer !== 'yes') {\n console.log('Protocol version has not been changed!');\n return void callback(0);\n }\n\n try {\n await states.setProtocolVersion(this.options.version as number);\n } catch (e) {\n console.error(`Cannot update protocol version: ${e.message}`);\n return void callback(1);\n }\n console.log(`States DB protocol updated to version ${this.options.version}`);\n return void callback(0);\n });\n }\n\n /**\n * Checks if state is a binary state\n *\n * @param id id of the state\n * @param objects the objects db\n * @param _obj cached object\n */\n private async _isBinary(id: string, objects: ObjectsClient, _obj?: ioBroker.AnyObject | null): Promise<boolean> {\n const obj = _obj || (await objects.getObject(id));\n\n return !!(obj && ('binary' in obj || (obj.common && 'type' in obj.common && obj.common.type === 'file')));\n }\n\n /**\n * Returns the value of a state\n *\n * @param args parsed cli arguments\n * @param resultTransform transform function for result\n */\n get_(args: string[], resultTransform: ResultTransform): void {\n const { callback, dbConnect } = this.options;\n const id = args[1];\n\n if (!id) {\n CLI.error.stateNotFound(id);\n return;\n }\n\n dbConnect(async params => {\n const { states, objects } = params;\n\n if (id.startsWith(ALIAS_STARTS_WITH)) {\n objects.getObject(id, (err, targetObj) => {\n // alias\n if (targetObj && targetObj.common && 'alias' in targetObj.common && targetObj.common.alias.id) {\n const aliasId =\n typeof targetObj.common.alias.id.read === 'string'\n ? targetObj.common.alias.id.read\n : targetObj.common.alias.id;\n objects.getObject(aliasId, async (_err, sourceObj) => {\n // read target\n try {\n if (await this._isBinary(aliasId, objects, targetObj)) {\n CLI.error.stateBinaryGetUnsupported(aliasId);\n return void callback(1);\n }\n\n const state = await states.getStateAsync(aliasId);\n if (!state) {\n CLI.error.stateNotFound(id);\n } else {\n tools.formatAliasValue({\n sourceCommon: sourceObj?.common as ioBroker.StateCommon | undefined,\n targetCommon: targetObj.common as ioBroker.StateCommon,\n state,\n logger: getLogger(),\n logNamespace: '',\n sourceId: sourceObj?._id,\n targetId: targetObj._id,\n });\n console.log(resultTransform(state));\n }\n } catch (e) {\n CLI.error.unknown(e);\n }\n return void callback(0);\n });\n } else {\n CLI.error.unknown(err?.message || `Alias ${id} has no target`);\n return void callback(1); // ?\n }\n });\n } else {\n try {\n if (await this._isBinary(id, objects)) {\n CLI.error.stateBinaryGetUnsupported(id);\n return void callback(1);\n }\n const state = await states.getStateAsync(id);\n if (!state) {\n CLI.error.stateNotFound(id);\n } else {\n console.log(resultTransform(state));\n }\n } catch (e) {\n CLI.error.unknown(e);\n }\n return void callback(0);\n }\n });\n }\n\n /**\n * Set state in database\n *\n * @param args parsed cli arguments\n */\n set_(args: string[]): void {\n const { callback, dbConnect, showHelp, value, ack: ackArg, id } = this.options;\n const force = args.includes('--force') || args.includes('-f');\n\n if (id === undefined) {\n CLI.error.requiredArgumentMissing('id');\n showHelp();\n return void callback(0);\n }\n\n if (value === undefined) {\n CLI.error.requiredArgumentMissing('value');\n showHelp();\n return void callback(0);\n }\n\n let ack = false;\n\n if (ackArg !== undefined) {\n ack = ackArg === 'true' || ackArg === 1;\n }\n\n dbConnect(params => {\n const { states, objects } = params;\n const newVal = { val: value, ack: !!ack };\n\n if (id.startsWith(ALIAS_STARTS_WITH)) {\n objects.getObject(id, async (_err, obj) => {\n if (await this._isBinary(id, objects, obj)) {\n CLI.error.stateBinarySetUnsupported(id);\n return void callback(1);\n }\n // alias\n if (obj?.common?.alias?.id) {\n const aliasId =\n typeof obj.common.alias.id.write === 'string'\n ? obj.common.alias.id.write\n : obj.common.alias.id;\n\n objects.getObject(aliasId, (err, targetObj) => {\n if (err) {\n CLI.error.unknown(err.message);\n return void callback(1); // access error\n }\n if (!obj && !force) {\n CLI.error.objectNotFound(id, 'null');\n return void callback(1); // object not exists\n }\n\n if (obj?.common?.type) {\n if (obj.common.type === 'string') {\n newVal.val = newVal.val.toString();\n } else if (obj.common.type === 'number') {\n newVal.val = Number(newVal.val);\n } else if (obj.common.type === 'boolean') {\n newVal.val = newVal.val.toString();\n newVal.val =\n newVal.val === 'true' ||\n newVal.val === '1' ||\n newVal.val === 'ON' ||\n newVal.val === 'on';\n }\n }\n\n // write target\n states.setState(\n aliasId,\n tools.formatAliasValue({\n sourceCommon: obj.common as ioBroker.StateCommon,\n targetCommon: targetObj?.common as ioBroker.StateCommon | undefined,\n state: newVal as ioBroker.State,\n logger: getLogger(),\n logNamespace: '',\n sourceId: obj._id,\n targetId: targetObj?._id,\n }),\n err => {\n if (err) {\n CLI.error.unknown(err.message);\n return void callback(1); // ?\n }\n CLI.success.stateUpdated(id, value, !!ack);\n return void callback(0);\n },\n );\n });\n } else {\n CLI.error.unknown(`Alias ${id} has no target`);\n return void callback(1); // ?\n }\n });\n } else {\n objects.getObject(id, async (err, obj) => {\n if (err) {\n CLI.error.unknown(err.message);\n return void callback(1); // access error\n }\n\n if (await this._isBinary(id, objects, obj)) {\n CLI.error.stateBinarySetUnsupported(id);\n return void callback(1);\n }\n\n if (!obj && !force) {\n CLI.error.objectNotFound(id, 'null');\n return void callback(1); // object not exists\n }\n\n if (obj?.common?.type) {\n if (obj.common.type === 'string') {\n newVal.val = newVal.val.toString();\n } else if (obj.common.type === 'number') {\n newVal.val = Number(newVal.val);\n } else if (obj.common.type === 'boolean') {\n newVal.val = newVal.val.toString();\n newVal.val =\n newVal.val === 'true' ||\n newVal.val === '1' ||\n newVal.val === 'ON' ||\n newVal.val === 'on';\n }\n }\n\n states.setState(id, newVal, err => {\n if (err) {\n CLI.error.unknown(err.message);\n return void callback(1); // ?\n }\n CLI.success.stateUpdated(id, value, !!ack);\n return void callback(0);\n });\n });\n }\n });\n }\n\n /**\n * Deletes a state\n *\n * @param args parsed cli arguments\n */\n delete(args: string[]): void {\n const { callback, dbConnect } = this.options;\n const id: string = args[1];\n if (!id) {\n CLI.error.requiredArgumentMissing('id', 'state delete id');\n return void callback(1);\n }\n\n dbConnect(params => {\n const { states } = params;\n\n states.delState(id, err => {\n if (err) {\n CLI.error.stateNotFound(id, err.message);\n return void callback(3);\n }\n CLI.success.stateDeleted(id);\n return void callback(0);\n });\n });\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;AAAA,kCAAsB;AACtB,wBAAmD;AAEnD,UAAqB;AACrB,sBAA4B;AAC5B,SAAoB;AACpB,mBAA0B;AAE1B,MAA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__getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
7
|
var __export = (target, all) => {
|
|
7
8
|
for (var name in all)
|
|
8
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -36,21 +37,26 @@ function formatValue(val, pretty = false) {
|
|
|
36
37
|
const output = !needsStringify ? val : pretty ? JSON.stringify(val, null, 2) : JSON.stringify(val);
|
|
37
38
|
return output;
|
|
38
39
|
}
|
|
40
|
+
__name(formatValue, "formatValue");
|
|
39
41
|
function getObjectFrom() {
|
|
40
42
|
return `system.host.${import_js_controller_common.tools.getHostName()}.cli`;
|
|
41
43
|
}
|
|
44
|
+
__name(getObjectFrom, "getObjectFrom");
|
|
42
45
|
function normalizeAdapterName(name) {
|
|
43
46
|
if (typeof name === "string") {
|
|
44
47
|
name = name.replace(new RegExp(`^${import_js_controller_common.tools.appName}\\.`, "i"), "");
|
|
45
48
|
}
|
|
46
49
|
return name;
|
|
47
50
|
}
|
|
51
|
+
__name(normalizeAdapterName, "normalizeAdapterName");
|
|
48
52
|
function validateAdapterIdentifier(name) {
|
|
49
53
|
return /^[a-z0-9\-_]+$/.test(name);
|
|
50
54
|
}
|
|
55
|
+
__name(validateAdapterIdentifier, "validateAdapterIdentifier");
|
|
51
56
|
function validateAdapterOrInstanceIdentifier(name) {
|
|
52
57
|
return /^[a-z0-9\-_]+(\.\d+)?$/.test(name);
|
|
53
58
|
}
|
|
59
|
+
__name(validateAdapterOrInstanceIdentifier, "validateAdapterOrInstanceIdentifier");
|
|
54
60
|
function splitAdapterOrInstanceIdentifierWithVersion(name) {
|
|
55
61
|
const res = name.match(/^([a-z0-9\-_]+)\.?(\d+)?@?([a-z0-9\-_.]*)?$/);
|
|
56
62
|
if (!res) {
|
|
@@ -63,17 +69,21 @@ function splitAdapterOrInstanceIdentifierWithVersion(name) {
|
|
|
63
69
|
nameWithVersion: `${res[1]}${res[3] ? `@${res[3]}` : ""}`
|
|
64
70
|
};
|
|
65
71
|
}
|
|
72
|
+
__name(splitAdapterOrInstanceIdentifierWithVersion, "splitAdapterOrInstanceIdentifierWithVersion");
|
|
66
73
|
function getInstanceName(instanceObjID) {
|
|
67
74
|
return instanceObjID.replace(/^system\.adapter\./i, "");
|
|
68
75
|
}
|
|
76
|
+
__name(getInstanceName, "getInstanceName");
|
|
69
77
|
async function enumInstances(objects, adapter) {
|
|
70
78
|
const startkey = `system.adapter.${adapter ? `${adapter}.` : ""}`;
|
|
71
79
|
const data = await enumObjects(objects, "instance", startkey);
|
|
72
80
|
return data.filter((it) => !!(it && it._id.startsWith(startkey)));
|
|
73
81
|
}
|
|
82
|
+
__name(enumInstances, "enumInstances");
|
|
74
83
|
function enumHosts(objects) {
|
|
75
84
|
return enumObjects(objects, "host", "system.host.");
|
|
76
85
|
}
|
|
86
|
+
__name(enumHosts, "enumHosts");
|
|
77
87
|
function enumObjects(objects, type, startkey) {
|
|
78
88
|
return new Promise((resolve, reject) => {
|
|
79
89
|
const endkey = `${startkey}\u9999`;
|
|
@@ -89,6 +99,7 @@ function enumObjects(objects, type, startkey) {
|
|
|
89
99
|
});
|
|
90
100
|
});
|
|
91
101
|
}
|
|
102
|
+
__name(enumObjects, "enumObjects");
|
|
92
103
|
// Annotate the CommonJS export names for ESM import in node:
|
|
93
104
|
0 && (module.exports = {
|
|
94
105
|
enumHosts,
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/cli/cliTools.ts"],
|
|
4
4
|
"sourcesContent": ["import { tools } from '@iobroker/js-controller-common';\nimport type { Client as ObjectsClient } from '@iobroker/db-objects-redis';\n\n/**\n *\n * @param val The value to format for output\n * @param pretty Whether it should be pretty-printed\n */\nexport function formatValue(val: any, pretty = false): string {\n // Only use JSON.stringify if we need it (for objects and arrays)\n const needsStringify = tools.isObject(val) || tools.isArray(val);\n const output = !needsStringify ? val : pretty ? JSON.stringify(val, null, 2) : JSON.stringify(val);\n return output;\n}\n\n/** Returns the \"from\" property for objects changed by the CLI */\nexport function getObjectFrom(): `system.host.${string}.cli` {\n return `system.host.${tools.getHostName()}.cli`;\n}\n\n/**\n * Removes <tools.appName> from the start of the adapter name if it is there\n * E.g. iobroker.admin -> admin\n *\n * @param name The adapter name to normalize\n */\nexport function normalizeAdapterName(name: string): string {\n if (typeof name === 'string') {\n name = name.replace(new RegExp(`^${tools.appName}\\\\.`, 'i'), '');\n }\n return name;\n}\n\n/**\n * Ensures that the given string is a valid adapter identifier (<adaptername>) WITHOUT instance number\n *\n * @param name The name which is supposed to be an adapter identifier\n */\nexport function validateAdapterIdentifier(name: string): boolean {\n return /^[a-z0-9\\-_]+$/.test(name);\n}\n\n/**\n * Ensures that the given string contains a valid identifier for\n * an adapter (without instance number) or instance (with instance number)\n *\n * @param name the adapter name or instance\n */\nexport function validateAdapterOrInstanceIdentifier(name: string): boolean {\n return /^[a-z0-9\\-_]+(\\.\\d+)?$/.test(name);\n}\n\n/**\n * Ensures that the given string contains a valid identifier for\n * an adapter (without instance number) or instance (with instance number)\n *\n * @param name the adapter name or instance\n */\nexport function splitAdapterOrInstanceIdentifierWithVersion(\n name: string,\n): { name: string; instance: string | null; version: string | null; nameWithVersion: string } | null {\n const res = name.match(/^([a-z0-9\\-_]+)\\.?(\\d+)?@?([a-z0-9\\-_.]*)?$/);\n if (!res) {\n return null;\n }\n return {\n name: res[1],\n instance: res[2] || null,\n version: res[3] || null,\n nameWithVersion: `${res[1]}${res[3] ? `@${res[3]}` : ''}`,\n };\n}\n\n/**\n * Extracts the instance name from an object ID\n *\n * @param instanceObjID The ID of the instance object\n */\nexport function getInstanceName(instanceObjID: string): string {\n return instanceObjID.replace(/^system\\.adapter\\./i, '');\n}\n\n/**\n * Enumerates the instances of an adapter or all of them\n *\n * @param objects The objects DB to use\n * @param adapter (optional) The adapter whose instances should be enumerated\n * @returns An array of instance objects\n */\nexport async function enumInstances(objects: ObjectsClient, adapter?: string): Promise<ioBroker.InstanceObject[]> {\n // if no adapter given all instances should be returned\n const startkey = `system.adapter.${adapter ? `${adapter}.` : ''}`;\n const data = await enumObjects(objects, 'instance', startkey);\n // because of startkey logic not only receive objects with the dot at the end, so filter them!\n return data.filter((it): it is ioBroker.InstanceObject => !!(it && it._id.startsWith(startkey)));\n}\n\n/**\n * Enumerates all known hosts\n *\n * @param objects The objects DB to use\n * @returns An array of host objects\n */\nexport function enumHosts(objects: ObjectsClient): Promise<ioBroker.InferGetObjectViewItemType<'system', 'host'>[]> {\n return enumObjects(objects, 'host', 'system.host.');\n}\n\n/**\n * Enumerates all objects of a given type\n *\n * @param objects The objects DB to use\n * @param type The type of the objects to enumerate\n * @param startkey The prefix of the objects\n */\nexport function enumObjects<T extends string>(\n objects: ObjectsClient,\n type: T,\n startkey: string,\n): Promise<ioBroker.InferGetObjectViewItemType<'system', T>[]> {\n return new Promise((resolve, reject) => {\n const endkey = `${startkey}\\u9999`;\n objects.getObjectView('system', type, { startkey, endkey }, null, (err, res) => {\n if (err) {\n return reject(err);\n }\n\n let ret: ioBroker.InferGetObjectViewItemType<'system', T>[] = [];\n if (res?.rows) {\n ret = res.rows.map(row => row.value);\n }\n resolve(ret);\n });\n });\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;AAAA,kCAAsB;AAQhB,SAAU,YAAY,KAAU,SAAS,OAAK;AAEhD,QAAM,iBAAiB,kCAAM,SAAS,GAAG,KAAK,kCAAM,QAAQ,GAAG;AAC/D,QAAM,SAAS,CAAC,iBAAiB,MAAM,SAAS,KAAK,UAAU,KAAK,MAAM,CAAC,IAAI,KAAK,UAAU,GAAG;AACjG,SAAO;AACX;AALgB;AAQV,SAAU,gBAAa;AACzB,SAAO,eAAe,kCAAM,YAAW,CAAE;AAC7C;AAFgB;AAUV,SAAU,qBAAqB,MAAY;AAC7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rB;AAEA,UAAI,MAA0D,CAAA;AAC9D,UAAI,KAAK,MAAM;AACX,cAAM,IAAI,KAAK,IAAI,SAAO,IAAI,KAAK;MACvC;AACA,cAAQ,GAAG;IACf,CAAC;EACL,CAAC;AACL;AAnBgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -3,6 +3,7 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
7
|
var __export = (target, all) => {
|
|
7
8
|
for (var name in all)
|
|
8
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -25,56 +26,56 @@ __export(messages_exports, {
|
|
|
25
26
|
module.exports = __toCommonJS(messages_exports);
|
|
26
27
|
var import_js_controller_common = require("@iobroker/js-controller-common");
|
|
27
28
|
const errorMessages = Object.freeze({
|
|
28
|
-
stateNotFound: (stateID, error2) => `The state ${stateID} was not found!${error2 ? ` Reason: ${error2}` : ""}`,
|
|
29
|
-
stateNotBinary: (stateId) => `State "${stateId}" is not binary.`,
|
|
30
|
-
stateBinaryGetUnsupported: (stateId) => `State "${stateId}" is a binary state, please use getBinary.`,
|
|
31
|
-
stateBinarySetUnsupported: (stateId) => `State "${stateId}" is a binary state and cannot be set via cli.`,
|
|
32
|
-
objectNotFound: (objectID, error2) => `The object ${objectID} was not found!${error2 ? ` Reason: ${error2}` : ""}`,
|
|
33
|
-
cannotUpdateObject: (objectID, error2) => `The object ${objectID} could not be updated!${error2 ? ` Reason: ${error2}` : ""}`,
|
|
34
|
-
cannotDeleteObject: (objectID, error2) => `The object ${objectID} cannot be deleted!${error2 ? ` Reason: ${error2}` : ""}`,
|
|
35
|
-
cannotDeleteObjectFromEnums: (objectID, error2) => `The object ${objectID} could not be deleted from enums!${error2 ? ` Reason: ${error2}` : ""}`,
|
|
36
|
-
cannotChangeObject: (objectID, error2) => `The object ${objectID} cannot be changed!${error2 ? ` Reason: ${error2}` : ""}`,
|
|
37
|
-
objectPropertyNotFound: (objectID, propPath) => `The requested property "${propPath}" or one of its parents was not found in the object "${objectID}"!`,
|
|
38
|
-
invalidPropertyOrValue: () => `The property path or value is not valid. Please make sure the value is valid JSON.`,
|
|
39
|
-
invalidJSONValue: () => `The given value is not valid JSON.`,
|
|
40
|
-
unknownCommand: (prefix, command) => `Unknown command "${prefix} ${command}"!`,
|
|
41
|
-
requiredArgumentMissing: (argName, exampleCommand) => `The required argument "${argName}" is missing!${exampleCommand ? ` Example: "${exampleCommand}"` : ""}`,
|
|
42
|
-
noInstancesFound: (adapter) => `Cannot find any instances of "${adapter}"!`,
|
|
43
|
-
invalidInstance: (instance) => `The instance "${instance}" does not exist!`,
|
|
44
|
-
specifyInstance: (adapter, adapterInstances) => `The adapter "${adapter}" has multiple instances! Please specify which one should be started: "${adapterInstances.join('", "')}".`,
|
|
45
|
-
adapterDirNotFound: (adapter) => `Cannot find the installation dir for adapter "${adapter}"!`,
|
|
46
|
-
mainFileNotFound: (adapter) => `Cannot find the main file for adapter "${adapter}"!`,
|
|
47
|
-
cannotLoadIoPackage: (adapter) => `Cannot load the io-package.json file for adapter "${adapter}"!`,
|
|
48
|
-
wrongCommandPrefix: (wrongPrefix, command, correctPrefix) => `The command ${command} is not intended to be used with ${wrongPrefix}!${correctPrefix ? ` Please use "${correctPrefix} ${command}" instead.` : ""}`,
|
|
49
|
-
unknown: (err) => `An unknown error occurred: ${err}`,
|
|
50
|
-
cannotChangeRunningSystem: () => `Cannot execute changes on running system. Stop ${import_js_controller_common.tools.appName} first.`,
|
|
51
|
-
noHostThisInMultihost: () => `Cannot use this command in multihost!`,
|
|
52
|
-
hostAlreadyExists: (hostname) => `A host with the name "${hostname}" already exists!`,
|
|
53
|
-
hostDoesNotExist: (hostname) => `The host "${hostname}" does not exist!`,
|
|
54
|
-
dontRemoveCurrentHost: (hostname) => `Cannot remove host "${hostname}" from itself!`,
|
|
55
|
-
pluginNotDefined: (pluginName, host, instance) => `The plugin "${pluginName}" does not exist for ${host ? `host "${host}"` : `instance "${instance}"`}!`,
|
|
56
|
-
cert: (certName) => `Certificate "${certName}" not found or error parsing certificate information.`,
|
|
57
|
-
instanceAlreadyRunning: (instance) => `The instance "${instance}" is already running, please stop instance first
|
|
29
|
+
stateNotFound: /* @__PURE__ */ __name((stateID, error2) => `The state ${stateID} was not found!${error2 ? ` Reason: ${error2}` : ""}`, "stateNotFound"),
|
|
30
|
+
stateNotBinary: /* @__PURE__ */ __name((stateId) => `State "${stateId}" is not binary.`, "stateNotBinary"),
|
|
31
|
+
stateBinaryGetUnsupported: /* @__PURE__ */ __name((stateId) => `State "${stateId}" is a binary state, please use getBinary.`, "stateBinaryGetUnsupported"),
|
|
32
|
+
stateBinarySetUnsupported: /* @__PURE__ */ __name((stateId) => `State "${stateId}" is a binary state and cannot be set via cli.`, "stateBinarySetUnsupported"),
|
|
33
|
+
objectNotFound: /* @__PURE__ */ __name((objectID, error2) => `The object ${objectID} was not found!${error2 ? ` Reason: ${error2}` : ""}`, "objectNotFound"),
|
|
34
|
+
cannotUpdateObject: /* @__PURE__ */ __name((objectID, error2) => `The object ${objectID} could not be updated!${error2 ? ` Reason: ${error2}` : ""}`, "cannotUpdateObject"),
|
|
35
|
+
cannotDeleteObject: /* @__PURE__ */ __name((objectID, error2) => `The object ${objectID} cannot be deleted!${error2 ? ` Reason: ${error2}` : ""}`, "cannotDeleteObject"),
|
|
36
|
+
cannotDeleteObjectFromEnums: /* @__PURE__ */ __name((objectID, error2) => `The object ${objectID} could not be deleted from enums!${error2 ? ` Reason: ${error2}` : ""}`, "cannotDeleteObjectFromEnums"),
|
|
37
|
+
cannotChangeObject: /* @__PURE__ */ __name((objectID, error2) => `The object ${objectID} cannot be changed!${error2 ? ` Reason: ${error2}` : ""}`, "cannotChangeObject"),
|
|
38
|
+
objectPropertyNotFound: /* @__PURE__ */ __name((objectID, propPath) => `The requested property "${propPath}" or one of its parents was not found in the object "${objectID}"!`, "objectPropertyNotFound"),
|
|
39
|
+
invalidPropertyOrValue: /* @__PURE__ */ __name(() => `The property path or value is not valid. Please make sure the value is valid JSON.`, "invalidPropertyOrValue"),
|
|
40
|
+
invalidJSONValue: /* @__PURE__ */ __name(() => `The given value is not valid JSON.`, "invalidJSONValue"),
|
|
41
|
+
unknownCommand: /* @__PURE__ */ __name((prefix, command) => `Unknown command "${prefix} ${command}"!`, "unknownCommand"),
|
|
42
|
+
requiredArgumentMissing: /* @__PURE__ */ __name((argName, exampleCommand) => `The required argument "${argName}" is missing!${exampleCommand ? ` Example: "${exampleCommand}"` : ""}`, "requiredArgumentMissing"),
|
|
43
|
+
noInstancesFound: /* @__PURE__ */ __name((adapter) => `Cannot find any instances of "${adapter}"!`, "noInstancesFound"),
|
|
44
|
+
invalidInstance: /* @__PURE__ */ __name((instance) => `The instance "${instance}" does not exist!`, "invalidInstance"),
|
|
45
|
+
specifyInstance: /* @__PURE__ */ __name((adapter, adapterInstances) => `The adapter "${adapter}" has multiple instances! Please specify which one should be started: "${adapterInstances.join('", "')}".`, "specifyInstance"),
|
|
46
|
+
adapterDirNotFound: /* @__PURE__ */ __name((adapter) => `Cannot find the installation dir for adapter "${adapter}"!`, "adapterDirNotFound"),
|
|
47
|
+
mainFileNotFound: /* @__PURE__ */ __name((adapter) => `Cannot find the main file for adapter "${adapter}"!`, "mainFileNotFound"),
|
|
48
|
+
cannotLoadIoPackage: /* @__PURE__ */ __name((adapter) => `Cannot load the io-package.json file for adapter "${adapter}"!`, "cannotLoadIoPackage"),
|
|
49
|
+
wrongCommandPrefix: /* @__PURE__ */ __name((wrongPrefix, command, correctPrefix) => `The command ${command} is not intended to be used with ${wrongPrefix}!${correctPrefix ? ` Please use "${correctPrefix} ${command}" instead.` : ""}`, "wrongCommandPrefix"),
|
|
50
|
+
unknown: /* @__PURE__ */ __name((err) => `An unknown error occurred: ${err}`, "unknown"),
|
|
51
|
+
cannotChangeRunningSystem: /* @__PURE__ */ __name(() => `Cannot execute changes on running system. Stop ${import_js_controller_common.tools.appName} first.`, "cannotChangeRunningSystem"),
|
|
52
|
+
noHostThisInMultihost: /* @__PURE__ */ __name(() => `Cannot use this command in multihost!`, "noHostThisInMultihost"),
|
|
53
|
+
hostAlreadyExists: /* @__PURE__ */ __name((hostname) => `A host with the name "${hostname}" already exists!`, "hostAlreadyExists"),
|
|
54
|
+
hostDoesNotExist: /* @__PURE__ */ __name((hostname) => `The host "${hostname}" does not exist!`, "hostDoesNotExist"),
|
|
55
|
+
dontRemoveCurrentHost: /* @__PURE__ */ __name((hostname) => `Cannot remove host "${hostname}" from itself!`, "dontRemoveCurrentHost"),
|
|
56
|
+
pluginNotDefined: /* @__PURE__ */ __name((pluginName, host, instance) => `The plugin "${pluginName}" does not exist for ${host ? `host "${host}"` : `instance "${instance}"`}!`, "pluginNotDefined"),
|
|
57
|
+
cert: /* @__PURE__ */ __name((certName) => `Certificate "${certName}" not found or error parsing certificate information.`, "cert"),
|
|
58
|
+
instanceAlreadyRunning: /* @__PURE__ */ __name((instance) => `The instance "${instance}" is already running, please stop instance first.`, "instanceAlreadyRunning")
|
|
58
59
|
});
|
|
59
60
|
const successMessages = Object.freeze({
|
|
60
|
-
objectUpdated: (objectID) => `The object "${objectID}" was updated successfully.`,
|
|
61
|
-
objectDeleted: (objectID) => `The object "${objectID}" was deleted.`,
|
|
62
|
-
stateUpdated: (stateID, value, ack) => `The state "${stateID}" was set to "${value}"${ack === void 0 ? "" : ` with flag ack=${ack}`}`,
|
|
63
|
-
stateDeleted: (stateID) => `The state "${stateID}" was deleted.`,
|
|
64
|
-
adapterStarted: (adapter) => `The adapter "${adapter}" was started.`,
|
|
65
|
-
adapterStopped: (adapter) => `The adapter "${adapter}" was stopped.`,
|
|
66
|
-
adapterRestarted: (adapter) => `The adapter "${adapter}" was restarted.`,
|
|
67
|
-
systemStatus: (isRunning) => isRunning ? `At least one ${import_js_controller_common.tools.appName} host is running.` : `No ${import_js_controller_common.tools.appName} host is running.`,
|
|
68
|
-
controllerStatus: (isRunning) => `${import_js_controller_common.tools.appName} is ${isRunning ? "" : "not "}running on this host.`,
|
|
69
|
-
messageSent: (adapter, command, message) => `The command "${command}" was sent to "${adapter}" with the message "${message}".`,
|
|
70
|
-
hostRenamed: (from, to) => `Host "${from}" successfully renamed to "${to}".`,
|
|
71
|
-
instanceHostChanged: (instance, from, to) => `The host for instance "${instance}" was changed from "${from}" to "${to}".`,
|
|
72
|
-
hostDeleted: (hostname) => `The host "${hostname}" was deleted.`,
|
|
73
|
-
pluginEnabledOrDisabled: (pluginName, host, instance, status) => `The plugin "${pluginName}" was successfully ${status ? "enabled" : "disabled"} for ${host ? `host "${host}"` : `instance "${instance}"`}.`,
|
|
74
|
-
pluginStatus: (pluginName, host, instance, status) => `The plugin "${pluginName}" is ${status ? "enabled" : "disabled"} for ${host ? `host "${host}"` : `instance "${instance}"`}
|
|
61
|
+
objectUpdated: /* @__PURE__ */ __name((objectID) => `The object "${objectID}" was updated successfully.`, "objectUpdated"),
|
|
62
|
+
objectDeleted: /* @__PURE__ */ __name((objectID) => `The object "${objectID}" was deleted.`, "objectDeleted"),
|
|
63
|
+
stateUpdated: /* @__PURE__ */ __name((stateID, value, ack) => `The state "${stateID}" was set to "${value}"${ack === void 0 ? "" : ` with flag ack=${ack}`}`, "stateUpdated"),
|
|
64
|
+
stateDeleted: /* @__PURE__ */ __name((stateID) => `The state "${stateID}" was deleted.`, "stateDeleted"),
|
|
65
|
+
adapterStarted: /* @__PURE__ */ __name((adapter) => `The adapter "${adapter}" was started.`, "adapterStarted"),
|
|
66
|
+
adapterStopped: /* @__PURE__ */ __name((adapter) => `The adapter "${adapter}" was stopped.`, "adapterStopped"),
|
|
67
|
+
adapterRestarted: /* @__PURE__ */ __name((adapter) => `The adapter "${adapter}" was restarted.`, "adapterRestarted"),
|
|
68
|
+
systemStatus: /* @__PURE__ */ __name((isRunning) => isRunning ? `At least one ${import_js_controller_common.tools.appName} host is running.` : `No ${import_js_controller_common.tools.appName} host is running.`, "systemStatus"),
|
|
69
|
+
controllerStatus: /* @__PURE__ */ __name((isRunning) => `${import_js_controller_common.tools.appName} is ${isRunning ? "" : "not "}running on this host.`, "controllerStatus"),
|
|
70
|
+
messageSent: /* @__PURE__ */ __name((adapter, command, message) => `The command "${command}" was sent to "${adapter}" with the message "${message}".`, "messageSent"),
|
|
71
|
+
hostRenamed: /* @__PURE__ */ __name((from, to) => `Host "${from}" successfully renamed to "${to}".`, "hostRenamed"),
|
|
72
|
+
instanceHostChanged: /* @__PURE__ */ __name((instance, from, to) => `The host for instance "${instance}" was changed from "${from}" to "${to}".`, "instanceHostChanged"),
|
|
73
|
+
hostDeleted: /* @__PURE__ */ __name((hostname) => `The host "${hostname}" was deleted.`, "hostDeleted"),
|
|
74
|
+
pluginEnabledOrDisabled: /* @__PURE__ */ __name((pluginName, host, instance, status) => `The plugin "${pluginName}" was successfully ${status ? "enabled" : "disabled"} for ${host ? `host "${host}"` : `instance "${instance}"`}.`, "pluginEnabledOrDisabled"),
|
|
75
|
+
pluginStatus: /* @__PURE__ */ __name((pluginName, host, instance, status) => `The plugin "${pluginName}" is ${status ? "enabled" : "disabled"} for ${host ? `host "${host}"` : `instance "${instance}"`}.`, "pluginStatus")
|
|
75
76
|
});
|
|
76
77
|
const warnings = Object.freeze({
|
|
77
|
-
noInstancesFoundOnHost: (hostname) => hostname ? `No instances found for host "${hostname}"!` : `No instances found
|
|
78
|
+
noInstancesFoundOnHost: /* @__PURE__ */ __name((hostname) => hostname ? `No instances found for host "${hostname}"!` : `No instances found!`, "noInstancesFoundOnHost")
|
|
78
79
|
});
|
|
79
80
|
const success = {};
|
|
80
81
|
for (const method of Object.keys(successMessages)) {
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/cli/messages.ts"],
|
|
4
4
|
"sourcesContent": ["import { tools } from '@iobroker/js-controller-common';\n\nconst errorMessages = Object.freeze({\n stateNotFound: (stateID: string, error?: string) =>\n `The state ${stateID} was not found!${error ? ` Reason: ${error}` : ''}`,\n stateNotBinary: (stateId: string) => `State \"${stateId}\" is not binary.`,\n stateBinaryGetUnsupported: (stateId: string) => `State \"${stateId}\" is a binary state, please use getBinary.`,\n stateBinarySetUnsupported: (stateId: string) => `State \"${stateId}\" is a binary state and cannot be set via cli.`,\n objectNotFound: (objectID: string, error?: string) =>\n `The object ${objectID} was not found!${error ? ` Reason: ${error}` : ''}`,\n cannotUpdateObject: (objectID: string, error?: string) =>\n `The object ${objectID} could not be updated!${error ? ` Reason: ${error}` : ''}`,\n cannotDeleteObject: (objectID: string, error?: string) =>\n `The object ${objectID} cannot be deleted!${error ? ` Reason: ${error}` : ''}`,\n cannotDeleteObjectFromEnums: (objectID: string, error?: string) =>\n `The object ${objectID} could not be deleted from enums!${error ? ` Reason: ${error}` : ''}`,\n cannotChangeObject: (objectID: string, error?: string) =>\n `The object ${objectID} cannot be changed!${error ? ` Reason: ${error}` : ''}`,\n objectPropertyNotFound: (objectID: string, propPath: string) =>\n `The requested property \"${propPath}\" or one of its parents was not found in the object \"${objectID}\"!`,\n invalidPropertyOrValue: () => `The property path or value is not valid. Please make sure the value is valid JSON.`,\n invalidJSONValue: () => `The given value is not valid JSON.`,\n\n unknownCommand: (prefix: string, command: string) => `Unknown command \"${prefix} ${command}\"!`,\n requiredArgumentMissing: (argName: string, exampleCommand?: string) =>\n `The required argument \"${argName}\" is missing!${exampleCommand ? ` Example: \"${exampleCommand}\"` : ''}`,\n\n noInstancesFound: (adapter: string) => `Cannot find any instances of \"${adapter}\"!`,\n invalidInstance: (instance: string) => `The instance \"${instance}\" does not exist!`,\n specifyInstance: (adapter: string, adapterInstances: string[]) =>\n `The adapter \"${adapter}\" has multiple instances! Please specify which one should be started: \"${adapterInstances.join(\n '\", \"',\n )}\".`,\n adapterDirNotFound: (adapter: string) => `Cannot find the installation dir for adapter \"${adapter}\"!`,\n mainFileNotFound: (adapter: string) => `Cannot find the main file for adapter \"${adapter}\"!`,\n cannotLoadIoPackage: (adapter: string) => `Cannot load the io-package.json file for adapter \"${adapter}\"!`,\n\n wrongCommandPrefix: (wrongPrefix: string, command: string, correctPrefix?: string) =>\n `The command ${command} is not intended to be used with ${wrongPrefix}!${\n correctPrefix ? ` Please use \"${correctPrefix} ${command}\" instead.` : ''\n }`,\n unknown: (err: string) => `An unknown error occurred: ${err}`,\n\n cannotChangeRunningSystem: () => `Cannot execute changes on running system. Stop ${tools.appName} first.`,\n noHostThisInMultihost: () => `Cannot use this command in multihost!`,\n hostAlreadyExists: (hostname: string) => `A host with the name \"${hostname}\" already exists!`,\n hostDoesNotExist: (hostname: string) => `The host \"${hostname}\" does not exist!`,\n dontRemoveCurrentHost: (hostname: string) => `Cannot remove host \"${hostname}\" from itself!`,\n\n pluginNotDefined: (pluginName: string, host: string, instance: string) =>\n `The plugin \"${pluginName}\" does not exist for ${host ? `host \"${host}\"` : `instance \"${instance}\"`}!`,\n\n cert: (certName: string) => `Certificate \"${certName}\" not found or error parsing certificate information.`,\n instanceAlreadyRunning: (instance: string) =>\n `The instance \"${instance}\" is already running, please stop instance first.`,\n});\n\nconst successMessages = Object.freeze({\n objectUpdated: (objectID: string) => `The object \"${objectID}\" was updated successfully.`,\n objectDeleted: (objectID: string) => `The object \"${objectID}\" was deleted.`,\n stateUpdated: (stateID: string, value: any, ack?: boolean) =>\n `The state \"${stateID}\" was set to \"${value}\"${ack === undefined ? '' : ` with flag ack=${ack}`}`,\n stateDeleted: (stateID: string) => `The state \"${stateID}\" was deleted.`,\n adapterStarted: (adapter: string) => `The adapter \"${adapter}\" was started.`,\n adapterStopped: (adapter: string) => `The adapter \"${adapter}\" was stopped.`,\n adapterRestarted: (adapter: string) => `The adapter \"${adapter}\" was restarted.`,\n systemStatus: (isRunning: boolean) =>\n isRunning ? `At least one ${tools.appName} host is running.` : `No ${tools.appName} host is running.`,\n controllerStatus: (isRunning: boolean) => `${tools.appName} is ${isRunning ? '' : 'not '}running on this host.`,\n messageSent: (adapter: string, command: string, message: string) =>\n `The command \"${command}\" was sent to \"${adapter}\" with the message \"${message}\".`,\n hostRenamed: (from: string, to: string) => `Host \"${from}\" successfully renamed to \"${to}\".`,\n instanceHostChanged: (instance: string, from: string, to: string) =>\n `The host for instance \"${instance}\" was changed from \"${from}\" to \"${to}\".`,\n hostDeleted: (hostname: string) => `The host \"${hostname}\" was deleted.`,\n\n pluginEnabledOrDisabled: (pluginName: string, host: string, instance: string, status: boolean) =>\n `The plugin \"${pluginName}\" was successfully ${status ? 'enabled' : 'disabled'} for ${\n host ? `host \"${host}\"` : `instance \"${instance}\"`\n }.`,\n pluginStatus: (pluginName: string, host: string, instance: string, status: boolean) =>\n `The plugin \"${pluginName}\" is ${status ? 'enabled' : 'disabled'} for ${\n host ? `host \"${host}\"` : `instance \"${instance}\"`\n }.`,\n});\n\nconst warnings = Object.freeze({\n noInstancesFoundOnHost: (hostname?: string) =>\n hostname ? `No instances found for host \"${hostname}\"!` : `No instances found!`,\n});\n\n// Capsule success messages in console.log\n/** Prints predefined success messages on the CLI */\nexport const success = {} as typeof successMessages;\nfor (const method of Object.keys(successMessages)) {\n // @ts-expect-error we are only using keys of sucessMessages so method is keyof\n success[method] = (...args: string[]) => console.log(successMessages[method](...args));\n}\n// warnings in console.warning\nexport const warn = {} as typeof warnings;\nfor (const method of Object.keys(warnings)) {\n // @ts-expect-error we are only using keys of sucessMessages so method is keyof\n warn[method] = (...args) => console.log(warnings[method](...args));\n}\n\n// error messages in console.error\n/** Prints predefined error messages on the CLI */\nexport const error = {} as typeof errorMessages;\nfor (const method of Object.keys(errorMessages)) {\n // @ts-expect-error we are only using keys of sucessMessages so method is keyof\n error[method] = (...args) => console.error(errorMessages[method](...args));\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;;;;;;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AAIO,MAAM,QAAQ,CAAA;AACrB,WAAW,UAAU,OAAO,KAAK,aAAa,GAAG;AAE7C,QAAM,MAAM,IAAI,IAAI,SAAS,QAAQ,MAAM,cAAc,MAAM,EAAE,GAAG,IAAI,CAAC;AAC7E;",
|
|
6
6
|
"names": ["error"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A single-line progress bar for terminals which can overwrite their own output.
|
|
3
|
+
*
|
|
4
|
+
* Used where the CLI has a long-running job with a known number of steps. When the output does not
|
|
5
|
+
* go to a terminal - a pipe, a log file, a CI job - a bar would only leave a trail of control
|
|
6
|
+
* characters, so callers ask {@link ProgressBar.isSupported} first and keep their line-based output
|
|
7
|
+
* otherwise.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Draws progress as a bar which overwrites its own line.
|
|
11
|
+
*
|
|
12
|
+
* Callers decide whether to use it - see {@link ProgressBar.isSupported} - and keep their own
|
|
13
|
+
* line-based output when the destination is not a terminal.
|
|
14
|
+
*/
|
|
15
|
+
export declare class ProgressBar {
|
|
16
|
+
private readonly label;
|
|
17
|
+
private readonly total;
|
|
18
|
+
private readonly stream;
|
|
19
|
+
/** Timestamp of the last redraw, to keep the throttle */
|
|
20
|
+
private lastRedraw;
|
|
21
|
+
/** Whether a bar is currently on screen and its line still open */
|
|
22
|
+
private open;
|
|
23
|
+
/**
|
|
24
|
+
* @param label Shown in front of the bar, e.g. the name of what is being uploaded
|
|
25
|
+
* @param total Number of steps that make up 100%
|
|
26
|
+
* @param stream Where to draw, defaults to stdout
|
|
27
|
+
*/
|
|
28
|
+
constructor(label: string, total: number, stream?: NodeJS.WriteStream);
|
|
29
|
+
/**
|
|
30
|
+
* Whether this stream can show a progress bar at all
|
|
31
|
+
*
|
|
32
|
+
* @param stream The stream the bar would be drawn to, defaults to stdout
|
|
33
|
+
*/
|
|
34
|
+
static isSupported(stream?: NodeJS.WriteStream): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Draw the current progress, throttled
|
|
37
|
+
*
|
|
38
|
+
* The last step is always drawn, so the bar never stops short of the number it ends on.
|
|
39
|
+
*
|
|
40
|
+
* @param done How many steps are finished
|
|
41
|
+
*/
|
|
42
|
+
update(done: number): void;
|
|
43
|
+
/**
|
|
44
|
+
* Close the line without completing the bar, so other output can be written
|
|
45
|
+
*
|
|
46
|
+
* Needed before an error or a warning is printed: without it the message would land in the
|
|
47
|
+
* middle of the bar and the next redraw would overwrite it.
|
|
48
|
+
*/
|
|
49
|
+
interrupt(): void;
|
|
50
|
+
/** Draw the bar as complete and close its line */
|
|
51
|
+
finish(): void;
|
|
52
|
+
/**
|
|
53
|
+
* Build the bar as it is written to the terminal
|
|
54
|
+
*
|
|
55
|
+
* @param done How many steps are finished
|
|
56
|
+
*/
|
|
57
|
+
private render;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=progressBar.d.ts.map
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var progressBar_exports = {};
|
|
21
|
+
__export(progressBar_exports, {
|
|
22
|
+
ProgressBar: () => ProgressBar
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(progressBar_exports);
|
|
25
|
+
const MIN_REDRAW_INTERVAL = 100;
|
|
26
|
+
const MIN_BAR_WIDTH = 10;
|
|
27
|
+
const DEFAULT_COLUMNS = 80;
|
|
28
|
+
const CR = "\r";
|
|
29
|
+
const CLEAR_TO_END = "\x1B[K";
|
|
30
|
+
class ProgressBar {
|
|
31
|
+
static {
|
|
32
|
+
__name(this, "ProgressBar");
|
|
33
|
+
}
|
|
34
|
+
label;
|
|
35
|
+
total;
|
|
36
|
+
stream;
|
|
37
|
+
/** Timestamp of the last redraw, to keep the throttle */
|
|
38
|
+
lastRedraw = 0;
|
|
39
|
+
/** Whether a bar is currently on screen and its line still open */
|
|
40
|
+
open = false;
|
|
41
|
+
/**
|
|
42
|
+
* @param label Shown in front of the bar, e.g. the name of what is being uploaded
|
|
43
|
+
* @param total Number of steps that make up 100%
|
|
44
|
+
* @param stream Where to draw, defaults to stdout
|
|
45
|
+
*/
|
|
46
|
+
constructor(label, total, stream = process.stdout) {
|
|
47
|
+
this.label = label;
|
|
48
|
+
this.total = total;
|
|
49
|
+
this.stream = stream;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Whether this stream can show a progress bar at all
|
|
53
|
+
*
|
|
54
|
+
* @param stream The stream the bar would be drawn to, defaults to stdout
|
|
55
|
+
*/
|
|
56
|
+
static isSupported(stream = process.stdout) {
|
|
57
|
+
return !!stream?.isTTY;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Draw the current progress, throttled
|
|
61
|
+
*
|
|
62
|
+
* The last step is always drawn, so the bar never stops short of the number it ends on.
|
|
63
|
+
*
|
|
64
|
+
* @param done How many steps are finished
|
|
65
|
+
*/
|
|
66
|
+
update(done) {
|
|
67
|
+
const now = Date.now();
|
|
68
|
+
if (this.open && done < this.total && now - this.lastRedraw < MIN_REDRAW_INTERVAL) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
this.lastRedraw = now;
|
|
72
|
+
this.open = true;
|
|
73
|
+
this.stream.write(`${CR}${this.render(done)}${CLEAR_TO_END}`);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Close the line without completing the bar, so other output can be written
|
|
77
|
+
*
|
|
78
|
+
* Needed before an error or a warning is printed: without it the message would land in the
|
|
79
|
+
* middle of the bar and the next redraw would overwrite it.
|
|
80
|
+
*/
|
|
81
|
+
interrupt() {
|
|
82
|
+
if (this.open) {
|
|
83
|
+
this.stream.write("\n");
|
|
84
|
+
this.open = false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/** Draw the bar as complete and close its line */
|
|
88
|
+
finish() {
|
|
89
|
+
this.stream.write(`${CR}${this.render(this.total)}${CLEAR_TO_END}
|
|
90
|
+
`);
|
|
91
|
+
this.open = false;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Build the bar as it is written to the terminal
|
|
95
|
+
*
|
|
96
|
+
* @param done How many steps are finished
|
|
97
|
+
*/
|
|
98
|
+
render(done) {
|
|
99
|
+
const percent = this.total > 0 ? Math.min(100, Math.floor(100 * done / this.total)) : 100;
|
|
100
|
+
const suffix = ` ${String(percent).padStart(3)}% (${done}/${this.total})`;
|
|
101
|
+
const prefix = `${this.label} `;
|
|
102
|
+
const columns = this.stream.columns || DEFAULT_COLUMNS;
|
|
103
|
+
const width = columns - prefix.length - suffix.length - 3;
|
|
104
|
+
if (width < MIN_BAR_WIDTH) {
|
|
105
|
+
return prefix + suffix.trimStart();
|
|
106
|
+
}
|
|
107
|
+
const filled = Math.round(width * percent / 100);
|
|
108
|
+
return `${prefix}[${"\u2588".repeat(filled)}${"\u2591".repeat(width - filled)}]${suffix}`;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
112
|
+
0 && (module.exports = {
|
|
113
|
+
ProgressBar
|
|
114
|
+
});
|
|
115
|
+
//# sourceMappingURL=progressBar.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/lib/progressBar.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * A single-line progress bar for terminals which can overwrite their own output.\n *\n * Used where the CLI has a long-running job with a known number of steps. When the output does not\n * go to a terminal - a pipe, a log file, a CI job - a bar would only leave a trail of control\n * characters, so callers ask {@link ProgressBar.isSupported} first and keep their line-based output\n * otherwise.\n */\n\n/** Redraw no more often than this, so a large job does not spend its time drawing, in ms */\nconst MIN_REDRAW_INTERVAL = 100;\n/** Below this width the bar carries no information and only the numbers are printed */\nconst MIN_BAR_WIDTH = 10;\n/** Assumed terminal width when the stream does not report one */\nconst DEFAULT_COLUMNS = 80;\n\n/** Move to the start of the line */\nconst CR = '\\r';\n/** Erase from the cursor to the end of the line, so a shorter line leaves no remains */\nconst CLEAR_TO_END = '\\u001B[K';\n\n/**\n * Draws progress as a bar which overwrites its own line.\n *\n * Callers decide whether to use it - see {@link ProgressBar.isSupported} - and keep their own\n * line-based output when the destination is not a terminal.\n */\nexport class ProgressBar {\n private readonly label: string;\n private readonly total: number;\n private readonly stream: NodeJS.WriteStream;\n\n /** Timestamp of the last redraw, to keep the throttle */\n private lastRedraw = 0;\n /** Whether a bar is currently on screen and its line still open */\n private open = false;\n\n /**\n * @param label Shown in front of the bar, e.g. the name of what is being uploaded\n * @param total Number of steps that make up 100%\n * @param stream Where to draw, defaults to stdout\n */\n constructor(label: string, total: number, stream: NodeJS.WriteStream = process.stdout) {\n this.label = label;\n this.total = total;\n this.stream = stream;\n }\n\n /**\n * Whether this stream can show a progress bar at all\n *\n * @param stream The stream the bar would be drawn to, defaults to stdout\n */\n static isSupported(stream: NodeJS.WriteStream = process.stdout): boolean {\n return !!stream?.isTTY;\n }\n\n /**\n * Draw the current progress, throttled\n *\n * The last step is always drawn, so the bar never stops short of the number it ends on.\n *\n * @param done How many steps are finished\n */\n update(done: number): void {\n const now = Date.now();\n\n if (this.open && done < this.total && now - this.lastRedraw < MIN_REDRAW_INTERVAL) {\n return;\n }\n\n this.lastRedraw = now;\n this.open = true;\n this.stream.write(`${CR}${this.render(done)}${CLEAR_TO_END}`);\n }\n\n /**\n * Close the line without completing the bar, so other output can be written\n *\n * Needed before an error or a warning is printed: without it the message would land in the\n * middle of the bar and the next redraw would overwrite it.\n */\n interrupt(): void {\n if (this.open) {\n this.stream.write('\\n');\n this.open = false;\n }\n }\n\n /** Draw the bar as complete and close its line */\n finish(): void {\n this.stream.write(`${CR}${this.render(this.total)}${CLEAR_TO_END}\\n`);\n this.open = false;\n }\n\n /**\n * Build the bar as it is written to the terminal\n *\n * @param done How many steps are finished\n */\n private render(done: number): string {\n const percent = this.total > 0 ? Math.min(100, Math.floor((100 * done) / this.total)) : 100;\n // padded, so the following text does not jump around while the number grows\n const suffix = ` ${String(percent).padStart(3)}% (${done}/${this.total})`;\n const prefix = `${this.label} `;\n const columns = this.stream.columns || DEFAULT_COLUMNS;\n // the two brackets, and one column kept free so the line cannot wrap\n const width = columns - prefix.length - suffix.length - 3;\n\n if (width < MIN_BAR_WIDTH) {\n return prefix + suffix.trimStart();\n }\n\n const filled = Math.round((width * percent) / 100);\n\n return `${prefix}[${'\u2588'.repeat(filled)}${'\u2591'.repeat(width - filled)}]${suffix}`;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;;;;;AAUA,MAAM,sBAAsB;AAE5B,MAAM,gBAAgB;AAEtB,MAAM,kBAAkB;AAGxB,MAAM,KAAK;AAEX,MAAM,eAAe;AAQf,MAAO,YAAW;EA3BxB,OA2BwB;;;EACH;EACA;EACA;;EAGT,aAAa;;EAEb,OAAO;;;;;;EAOf,YAAY,OAAe,OAAe,SAA6B,QA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
|
|
7
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { EXIT_CODES } from '@iobroker/js-controller-common';
|
|
2
|
+
/** Options for creating an {@link IoBrokerError} */
|
|
2
3
|
export interface IoBrokerErrorOptions {
|
|
3
4
|
/** The error message */
|
|
4
5
|
message: string;
|
|
@@ -10,6 +11,9 @@ export interface IoBrokerErrorOptions {
|
|
|
10
11
|
*/
|
|
11
12
|
export declare class IoBrokerError extends Error {
|
|
12
13
|
readonly code: EXIT_CODES;
|
|
14
|
+
/**
|
|
15
|
+
* @param options The error message and ioBroker exit code
|
|
16
|
+
*/
|
|
13
17
|
constructor(options: IoBrokerErrorOptions);
|
|
14
18
|
}
|
|
15
19
|
//# sourceMappingURL=customError.d.ts.map
|
|
@@ -3,6 +3,7 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
7
|
var __export = (target, all) => {
|
|
7
8
|
for (var name in all)
|
|
8
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -22,7 +23,13 @@ __export(customError_exports, {
|
|
|
22
23
|
});
|
|
23
24
|
module.exports = __toCommonJS(customError_exports);
|
|
24
25
|
class IoBrokerError extends Error {
|
|
26
|
+
static {
|
|
27
|
+
__name(this, "IoBrokerError");
|
|
28
|
+
}
|
|
25
29
|
code;
|
|
30
|
+
/**
|
|
31
|
+
* @param options The error message and ioBroker exit code
|
|
32
|
+
*/
|
|
26
33
|
constructor(options) {
|
|
27
34
|
super(options.message);
|
|
28
35
|
this.name = this.constructor.name;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/setup/customError.ts"],
|
|
4
|
-
"sourcesContent": ["import type { EXIT_CODES } from '@iobroker/js-controller-common';\n\nexport interface IoBrokerErrorOptions {\n /** The error message */\n message: string;\n /** An ioBroker error code */\n code: EXIT_CODES;\n}\n\n/**\n * A custom ioBroker CLI error to propagate the exit code down\n */\nexport class IoBrokerError extends Error {\n readonly code: EXIT_CODES;\n constructor(options: IoBrokerErrorOptions) {\n super(options.message);\n\n this.name = this.constructor.name;\n\n Error.captureStackTrace(this, this.constructor);\n\n // you may also assign additional properties to your error\n this.code = options.code;\n }\n}\n"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import type { EXIT_CODES } from '@iobroker/js-controller-common';\n\n/** Options for creating an {@link IoBrokerError} */\nexport interface IoBrokerErrorOptions {\n /** The error message */\n message: string;\n /** An ioBroker error code */\n code: EXIT_CODES;\n}\n\n/**\n * A custom ioBroker CLI error to propagate the exit code down\n */\nexport class IoBrokerError extends Error {\n readonly code: EXIT_CODES;\n /**\n * @param options The error message and ioBroker exit code\n */\n constructor(options: IoBrokerErrorOptions) {\n super(options.message);\n\n this.name = this.constructor.name;\n\n Error.captureStackTrace(this, this.constructor);\n\n // you may also assign additional properties to your error\n this.code = options.code;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAUA;;;;;AAGM,MAAO,sBAAsB,MAAK;EAHxC,OAGwC;;;EAC3B;;;;EAIT,YAAY,SAA6B;AACrC,UAAM,QAAQ,OAAO;AAErB,SAAK,OAAO,KAAK,YAAY;AAE7B,UAAM,kBAAkB,MAAM,KAAK,WAAW;AAG9C,SAAK,OAAO,QAAQ;EACxB;;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|