From e49823921d9c9b576475b6b22fca797a8933512f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dandelion=20Man=C3=A9?= Date: Sat, 13 Jun 2020 19:46:43 -0700 Subject: [PATCH] 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. --- src/cli2/load.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/cli2/load.js b/src/cli2/load.js index 710326e..e49e3c6 100644 --- a/src/cli2/load.js +++ b/src/cli2/load.js @@ -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);