Filter nested entrypoints on getCommands(). Used by help.

This commit is contained in:
Frank Schmid 2017-06-07 17:19:17 +02:00
parent 7e65a22a8b
commit b73466641e

View File

@ -173,9 +173,26 @@ class PluginManager {
}
getCommands() {
// Return filtered list of visible commands
const cmds = _.omitBy(this.commands, ['type', 'entrypoint']);
return cmds;
const result = {};
// Iterate through the commands and stop at entrypoints to include only public
// command throughout the hierarchy.
const stack = [{ commands: this.commands, target: result }];
while (!_.isEmpty(stack)) {
const currentCommands = stack.pop();
const commands = currentCommands.commands;
const target = currentCommands.target;
_.forOwn(commands, (command, name) => {
if (command.type !== 'entrypoint') {
_.set(target, name, _.omit(command, 'commands'));
if (_.some(command.commands, childCommand => childCommand.type !== 'entrypoint')) {
target[name].commands = {};
stack.push({ commands: command.commands, target: target[name].commands });
}
}
});
}
return result;
}
/**