@puls-atlas/cli
Version:
The Puls Atlas CLI tool for managing Atlas projects
24 lines • 937 B
JavaScript
const isCommandLike = value => value !== null && typeof value === 'object' && typeof value.opts === 'function';
const collectCommandLineage = command => {
const lineage = [];
let currentCommand = command;
while (isCommandLike(currentCommand)) {
lineage.unshift(currentCommand);
currentCommand = currentCommand.parent ?? null;
}
return lineage;
};
export const resolveCommandActionOptions = (options = {}, command = null) => {
const actionCommand = isCommandLike(command) ? command : isCommandLike(options) ? options : null;
if (!actionCommand) {
return {
...(options ?? {})
};
}
const resolvedOptions = {};
for (const lineageCommand of collectCommandLineage(actionCommand)) {
Object.assign(resolvedOptions, lineageCommand.opts());
}
return resolvedOptions;
};
export const createOptionsOnlyAction = handler => (options, command) => handler(resolveCommandActionOptions(options, command));