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:
parent
dd76595ac2
commit
e49823921d
|
@ -1,5 +1,6 @@
|
||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
|
import * as NullUtil from "../util/null";
|
||||||
import type {Command} from "./command";
|
import type {Command} from "./command";
|
||||||
import {loadInstanceConfig, pluginDirectoryContext} from "./common";
|
import {loadInstanceConfig, pluginDirectoryContext} from "./common";
|
||||||
import {LoggingTaskReporter} from "../util/taskReporter";
|
import {LoggingTaskReporter} from "../util/taskReporter";
|
||||||
|
@ -10,15 +11,28 @@ function die(std, message) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const loadCommand: Command = async (args, std) => {
|
const loadCommand: Command = async (args, std) => {
|
||||||
if (args.length !== 0) {
|
let pluginsToLoad = [];
|
||||||
return die(std, "usage: sourcecred load");
|
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();
|
const taskReporter = new LoggingTaskReporter();
|
||||||
taskReporter.start("load");
|
taskReporter.start("load");
|
||||||
const baseDir = process.cwd();
|
|
||||||
const config = await loadInstanceConfig(baseDir);
|
|
||||||
const loadPromises = [];
|
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}`;
|
const task = `loading ${name}`;
|
||||||
taskReporter.start(task);
|
taskReporter.start(task);
|
||||||
const dirContext = pluginDirectoryContext(baseDir, name);
|
const dirContext = pluginDirectoryContext(baseDir, name);
|
||||||
|
|
Loading…
Reference in New Issue