Skip to content

Commit

Permalink
Merge pull request #561 from mountaindude/522
Browse files Browse the repository at this point in the history
feat(qseow): Add `--new-app-delete` option to `qseow field-scramble` …
  • Loading branch information
mountaindude authored Nov 26, 2024
2 parents ca915b9 + 996df4f commit 7d32d1a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 10 deletions.
21 changes: 12 additions & 9 deletions src/lib/cli/qseow-scramble-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,29 @@ export function setupQseowScrambleFieldCommand(qseow) {
.requiredOption('--app-id <id>', 'Qlik Sense app ID to be scrambled')
.requiredOption('--field-name <names...>', 'name of field(s) to be scrambled')
.requiredOption('--new-app-name <name>', 'name of new app that will contain scrambled data. Not used if --new-app-cmd=replace')
.option(
'--new-app-delete',
'should the new scrambled app be deleted after the operation is complete? If not, the new app will be placed in the My Work stream'
)

.addOption(
new Option(
'--new-app-cmd <command>',
'what to do with the new app. If nothing is specified in this option the new app will be placed in My Work. WHen specifying "replace": If the replaced app is published, only the sheets that were originally published with the app are replaced. If the replaced app is not published, the entire app is replaced.'
'what to do with the new app. If nothing is specified in this option the new app will be placed in My Work.\n"publish": publish the new app to the stream specified by --new-app-cmd-id or --new-app-cmd-name. The new app will NOT remain in My Work.\n"replace": Replace an existing published or unpublished app. If the app is published, only the sheets that were originally published with the app are replaced. If the replaced app is not published, the entire app is replaced.'
)
.choices(['publish', 'replace'])
.choices(['', 'publish', 'replace'])
.default('')
)

.addOption(
new Option('--new-app-cmd-id <id>', 'stream/app ID that --new-app-cmd acts on. Cannot be used with --new-app-cmd-name').default(
''
)
new Option('--new-app-cmd-id <id>', 'stream/app ID that --new-app-cmd acts on. Cannot be used with --new-app-cmd-name')
.default('')
.conflicts('new-app-cmd-name')
)
.addOption(
new Option(
'--new-app-cmd-name <name>',
'stream/app name that --new-app-cmd acts on. Cannot be used with --new-app-cmd-id'
).default('')
new Option('--new-app-cmd-name <name>', 'stream/app name that --new-app-cmd acts on. Cannot be used with --new-app-cmd-id')
.default('')
.conflicts('new-app-cmd-id')
)

.addOption(new Option('--force', 'force delete and replace operations to proceed without asking for confirmation'));
Expand Down
36 changes: 36 additions & 0 deletions src/lib/cmd/qseow/scramblefield.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,42 @@ export async function scrambleField(options) {
}
}
}

// Finally, should the new app be deleted?
// This is specified with the --new-app-delete option
if (options.newAppDelete) {
// Delete the new app
if (!options.force) {
const answer = await yesno({
question: `Do you want to delete the new, scrambled app "${options.newAppName}" with app ID ${newAppId}? (y/n)`,
});

if (answer) {
const resultDelete = await deleteAppById(newAppId, options);
if (resultDelete) {
logger.info(`Deleted new, scrambled app "${options.newAppName}" with app ID ${newAppId}`);
scrambleResult.status = 'success';
} else {
logger.error(`Error deleting new, scrambled app "${options.newAppName}" with app ID ${newAppId}`);
scrambleResult.status = 'error';
}
} else {
logger.warn(
`Did not delete new, scrambled app "${options.newAppName}" with app ID ${newAppId}. The app is still available in My Work.`
);
scrambleResult.status = 'aborted';
}
} else {
const resultDelete = await deleteAppById(newAppId, options);
if (resultDelete) {
logger.info(`Deleted new, scrambled app "${options.newAppName}" with app ID ${newAppId}`);
scrambleResult.status = 'success';
} else {
logger.error(`Error deleting new, scrambled app "${options.newAppName}" with app ID ${newAppId}`);
scrambleResult.status = 'error';
}
}
}
}

// Return the result of the scramble operation
Expand Down
2 changes: 1 addition & 1 deletion src/lib/util/qseow/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export async function getAppById(appId, optionsParam) {

return false;
} catch (err) {
catchLog('GET APP BY ID', err);
// catchLog('GET APP BY ID', err);
return false;
}
}
Expand Down

0 comments on commit 7d32d1a

Please sign in to comment.