Skip to content

Commit

Permalink
feat: Better valid options checking for get-task command
Browse files Browse the repository at this point in the history
Implements #171
  • Loading branch information
Göran Sander committed Feb 14, 2023
1 parent 353aabe commit 93a817f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/lib/util/assert-options.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const path = require('path');
const uuidVersion = require('uuid').version;
const uuidValidate = require('uuid').validate;

const { logger, execPath, verifyFileExists } = require('../../globals');

Expand Down Expand Up @@ -132,6 +134,29 @@ const getTaskAssertOptions = (options) => {
logger.error('Task tree view is not supported when specifying task IDs and/or task tags. Exiting.');
process.exit(1);
}

// Verify all task IDs are valid uuids
// eslint-disable-next-line no-restricted-syntax
for (const taskId of options.taskId) {
if (!uuidValidate(taskId)) {
logger.error(`Invalid format of task ID parameter "${taskId}". Exiting.`);
process.exit(1);
} else {
logger.verbose(`Task id "${taskId}" is a valid uuid version ${uuidVersion(taskId)}`);
}
}
}

// --table-details not allowed when --output-format is set to tree.
if (options.outputFormat === 'tree' && options.tableDetails) {
logger.error(`--table-details not allowed when --output-format is set to tree. Exiting.`);
process.exit(1);
}

// --tree-details not allowed when --output-format is set to table.
if (options.outputFormat === 'table' && options.treeDetails) {
logger.error(`--tree-details not allowed when --output-format is set to table. Exiting.`);
process.exit(1);
}
};

Expand Down

0 comments on commit 93a817f

Please sign in to comment.