cli2 load: support loading specific plugins (#1858)

This modifies cli2/load so that you can now provide a list of fully
scoped plugin names (e.g. sourcecred/github) and it will load only the
mentioned plugins. If any plugins aren't available, an error is thrown.
If no plugins are listed, all of the activated plugins are loaded.

Test plan: Tested locally in success and failure cases. No unit tests
atm, which matches the rest of cli2--tbh this feels like the kind of
code where the liklihood of subtle failures or regressions is low, and
it's a pain to test, so I'm content with the status quo for now.
This commit is contained in:
Dandelion Mané 2020-06-13 19:46:43 -07:00 committed by GitHub
parent dd76595ac2
commit e49823921d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 5 deletions

View File

@ -1,5 +1,6 @@
// @flow
import * as NullUtil from "../util/null";
import type {Command} from "./command";
import {loadInstanceConfig, pluginDirectoryContext} from "./common";
import {LoggingTaskReporter} from "../util/taskReporter";
@ -10,15 +11,28 @@ function die(std, message) {
}
const loadCommand: Command = async (args, std) => {
if (args.length !== 0) {
return die(std, "usage: sourcecred load");
let pluginsToLoad = [];
const baseDir = process.cwd();
const config = await loadInstanceConfig(baseDir);
if (args.length === 0) {
pluginsToLoad = config.bundledPlugins.keys();
} else {
for (const arg of args) {
if (config.bundledPlugins.has(arg)) {
pluginsToLoad.push(arg);
} else {
return die(
std,
`can't find plugin ${arg}; remember to use fully scoped name, as in sourcecred/github`
);
}
}
}
const taskReporter = new LoggingTaskReporter();
taskReporter.start("load");
const baseDir = process.cwd();
const config = await loadInstanceConfig(baseDir);
const loadPromises = [];
for (const [name, plugin] of config.bundledPlugins) {
for (const name of pluginsToLoad) {
const plugin = NullUtil.get(config.bundledPlugins.get(name));
const task = `loading ${name}`;
taskReporter.start(task);
const dirContext = pluginDirectoryContext(baseDir, name);