From ec9f1ad4c8b218f8961761ba971a1f9ad91c7381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ran=20Sander?= Date: Sun, 10 Mar 2024 16:23:55 +0000 Subject: [PATCH 1/3] fix: Improve help texts for and sort available sub-commands in help texts. Fixes #431 --- src/ctrl-q.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/ctrl-q.js b/src/ctrl-q.js index cb706ce..0341558 100644 --- a/src/ctrl-q.js +++ b/src/ctrl-q.js @@ -46,6 +46,17 @@ import { const program = new Command(); +// Set the name of the program (to be used in help text) +program.name('ctrl-q'); + +// Set help text to be shown after errors +program.showHelpAfterError('(add --help for additional information about required and optional parameters)'); + +// Help text configuration +program.configureHelp({ + sortSubcommands: true, +}); + /** * Top level async function. * Workaround to deal with the fact that Node.js doesn't currently support top level async functions... From 6615afa9edee6f42496a4bc3f35b1ba9a0abb8f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ran=20Sander?= Date: Sun, 10 Mar 2024 19:07:37 +0000 Subject: [PATCH 2/3] fix(variable-get): Now possible to get variables from more than one app in a single Ctrl-Q execution Fixes #430 --- src/lib/cmd/getvariable.js | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/lib/cmd/getvariable.js b/src/lib/cmd/getvariable.js index e871b48..f3b4132 100644 --- a/src/lib/cmd/getvariable.js +++ b/src/lib/cmd/getvariable.js @@ -53,6 +53,8 @@ const getVariable = async (options) => { // Get IDs of all apps that should be processed const apps = await getApps(options, options.appId, options.appTag); + logger.info(`Found ${apps.length} apps to process`); + // Session ID to use when connecting to the Qlik Sense server const sessionId = 'ctrlq'; @@ -75,7 +77,7 @@ const getVariable = async (options) => { try { global = await session.open(); } catch (err) { - catchLog(`Error opening session to server ${options.host}`, err); + catchLog(`Error opening session (1) to server ${options.host}`, err); process.exit(1); } @@ -92,6 +94,25 @@ const getVariable = async (options) => { let subsetVariables = []; for (const app of apps) { + logger.info(`Getting variables from app ${app.id}, "${app.name}"`); + + // Do we already have a session, or do we need to open a new one? + if (session.globalPromise === undefined) { + // Create new session to Sense engine + try { + session = await enigma.create(configEnigma); + logger.verbose(`Created new session to server ${options.host}.`); + + global = await session.open(); + logger.verbose(`Opened new session to server ${options.host}.`); + + engineVersion = await global.engineVersion(); + } catch (err) { + catchLog(`Error opening session (2) to server ${options.host}`, err); + process.exit(1); + } + } + // Open app without data const doc = await global.openDoc(app.id, '', '', '', true); logger.verbose(`Opened app ${app.id}, "${app.name}".`); @@ -127,7 +148,8 @@ const getVariable = async (options) => { allVariables = allVariables.concat({ appId: app.id, appName: app.name, variables: appVariablesLayout.qVariableList.qItems }); // Close app session - // doc.session.close(); + // await doc.session.close(); + await session.close(); } if (options.variable === undefined) { @@ -242,10 +264,12 @@ const getVariable = async (options) => { logger.error('Undefined --output-format option'); } - if ((await session.close()) === true) { - logger.verbose(`Closed session after getting master item measures in app ${options.appId} on host ${options.host}`); - } else { - logger.error(`Error closing session for app ${options.appId} on host ${options.host}`); + if (session.globalPromise !== undefined) { + if ((await session.close()) === true) { + logger.verbose(`Closed session after getting app variables.`); + } else { + logger.error(`Error closing session for app ${options.appId} on host ${options.host}`); + } } } catch (err) { catchLog(`Error in getVariable`, err); From 3bbcf91c3c255317dbe3bc1fb4d042a0e3b4295b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ran=20Sander?= Date: Sun, 10 Mar 2024 19:13:57 +0000 Subject: [PATCH 3/3] refactor(variable-get): Add a bit more verbose logging about Sense and engine versions --- src/lib/cmd/getvariable.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/lib/cmd/getvariable.js b/src/lib/cmd/getvariable.js index f3b4132..82bfc5d 100644 --- a/src/lib/cmd/getvariable.js +++ b/src/lib/cmd/getvariable.js @@ -82,9 +82,18 @@ const getVariable = async (options) => { } let engineVersion; + let productVersion; + let qTProduct; + let qvVersion; try { engineVersion = await global.engineVersion(); logger.verbose(`Server ${options.host} has engine version ${engineVersion.qComponentVersion}.`); + + productVersion = await global.productVersion(); + logger.verbose(`Server ${options.host} has product version ${productVersion}.`); + + qTProduct = await global.qTProduct(); + logger.verbose(`Server ${options.host} product name: ${qTProduct}.`); } catch (err) { catchLog(`Error getting engine version from server ${options.host}`, err); process.exit(1);