feat: autocomplete for activate/reset

useless features™️
isekai-main
Julian Lam 3 years ago
parent fdae69911b
commit f0d192fbfd

@ -25,6 +25,9 @@ async function activate(plugin) {
// Allow omission of `nodebb-plugin-`
plugin = `nodebb-plugin-${plugin}`;
}
plugin = await plugins.autocomplete(plugin);
const isInstalled = await plugins.isInstalled(plugin);
if (!isInstalled) {
throw new Error('plugin not installed');

@ -25,6 +25,7 @@ exports.reset = async function (options) {
themeId = `nodebb-theme-${themeId}`;
}
themeId = await plugins.autocomplete(themeId);
await resetTheme(themeId);
}
},
@ -38,6 +39,7 @@ exports.reset = async function (options) {
pluginId = `nodebb-plugin-${pluginId}`;
}
pluginId = await plugins.autocomplete(pluginId);
await resetPlugin(pluginId);
}
},

@ -2,7 +2,7 @@
const winston = require('winston');
const path = require('path');
const fs = require('fs');
const fs = require('fs').promises;
const nconf = require('nconf');
const os = require('os');
const cproc = require('child_process');
@ -137,7 +137,7 @@ module.exports = function (Plugins) {
Plugins.isInstalled = async function (id) {
const pluginDir = path.join(paths.nodeModules, id);
try {
const stats = await fs.promises.stat(pluginDir);
const stats = await fs.stat(pluginDir);
return stats.isDirectory();
} catch (err) {
return false;
@ -151,4 +151,12 @@ module.exports = function (Plugins) {
Plugins.getActive = async function () {
return await db.getSortedSetRange('plugins:active', 0, -1);
};
Plugins.autocomplete = async (fragment) => {
const pluginDir = paths.nodeModules;
const plugins = (await fs.readdir(pluginDir)).filter(filename => filename.startsWith(fragment));
// Autocomplete only if single match
return plugins.length === 1 ? plugins.pop() : fragment;
};
};

Loading…
Cancel
Save