-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Adds ability to list installed plugins from CLI #5920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
8fda0f9
0e14e41
ea0f2ef
d09f83b
2e9f00f
5bfccda
42334e3
cac0f06
ff15794
220fc8b
b9a8098
cbc3350
f8ba6ca
13c0ccc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| const fs = require('fs'); | ||
|
|
||
| export function list(settings, logger) { | ||
| const files = fs.readdirSync(settings.pluginDir); | ||
| files | ||
| .filter(function (file) { | ||
| return file[0] !== '.'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you only need the first value of the file array, I'd recommend destructuring the array argument so this conditional becomes a bit more expressive: .filter(function([ fileName ]) {
return fileName !== '.';
});
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I think I can remove this filter altogether. It was meant to check if the first character of a filename is
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I totally misunderstood what this filter was even doing. Remove it if you think that's OK, but you definitely should not try to take my advice on this. If you do need to keep the check, I'd recommend using lodash's |
||
| }) | ||
| .forEach(function (pluginFile) { | ||
| logger.log(pluginFile); | ||
| }); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,16 @@ export default function createSettingParser(options) { | |
| return 'https://download.elastic.co/' + settings.organization + '/' + settings.package + '/' + filename; | ||
| } | ||
|
|
||
| function areMultipleOptionsChosen(options, choices) { | ||
| let numChosen = 0; | ||
| choices.forEach(function (choice) { | ||
| if (options[choice]) { | ||
| ++numChosen; | ||
| } | ||
| }); | ||
| return (numChosen > 1); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd recommend doing this by checking the length of the intersection rather than imperatively counting the duplicates. You can import function areMultipleOptionsChosen(options, choices) {
return intersection(Object.keys(options), choices).length > 1;
}
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Beautiful. Changing. Thanks! |
||
| } | ||
|
|
||
| function parse() { | ||
| let parts; | ||
| let settings = { | ||
|
|
@@ -84,8 +94,12 @@ export default function createSettingParser(options) { | |
| settings.package = parts.shift(); | ||
| } | ||
|
|
||
| if (!settings.action || (options.install && options.remove)) { | ||
| throw new Error('Please specify either --install or --remove.'); | ||
| if (options.list) { | ||
| settings.action = 'list'; | ||
| } | ||
|
|
||
| if (!settings.action || areMultipleOptionsChosen(options, [ 'install', 'remove', 'list' ])) { | ||
| throw new Error('Please specify either --install, --remove, or --list.'); | ||
| } | ||
|
|
||
| settings.pluginDir = options.pluginDir; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I apologize for not catching this in the first go around, but I didn't notice it until you chained these together. If you're chaining anyway, you might as well ditch the local variable entirely:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okie doke. Changing.