* Get all available commands or options depends on entered input * @param optionsAndArgs - object of available options and arguments * - name - generator name * - options - list of option objects * - arguments - list of argument objects * @param partial - completion env.partial
(optionsAndArgs, partial)
| 23 | * @param partial - completion env.partial |
| 24 | */ |
| 25 | function generateCompletions(optionsAndArgs, partial) { |
| 26 | // Remove the `base` |
| 27 | delete optionsAndArgs.base; |
| 28 | const commands = Object.keys(optionsAndArgs); |
| 29 | const enteredCommand = commands.find(command => partial.includes(command)); |
| 30 | |
| 31 | if (!enteredCommand) { |
| 32 | return commands; |
| 33 | } |
| 34 | |
| 35 | const options = optionsAndArgs[enteredCommand].options; |
| 36 | const optionNames = Object.keys(options).map(opt => `--${opt}`); |
| 37 | |
| 38 | const enteredOptions = optionNames.filter(opt => partial.includes(opt)); |
| 39 | |
| 40 | if (!enteredOptions.length) { |
| 41 | return optionNames; |
| 42 | } |
| 43 | |
| 44 | return optionNames.filter(opt => !enteredOptions.includes(opt)); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Process bash-completion and take care about logging available commands |
no test coverage detected