beeline-cli
Version:
A terminal wallet for the Hive blockchain - type, sign, rule the chain
93 lines • 4.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@oclif/core");
const simple_plugins_js_1 = require("../utils/simple-plugins.js");
const neon_js_1 = require("../utils/neon.js");
class RunPlugin extends core_1.Command {
async run() {
const theme = await (0, neon_js_1.getTheme)();
// Parse raw process arguments to bypass OCLIF's flag validation
// Find the run-plugin command position and extract everything after it
const processArgs = process.argv;
const runPluginIndex = processArgs.findIndex(arg => arg === 'run-plugin');
if (runPluginIndex === -1 || runPluginIndex + 1 >= processArgs.length) {
console.log(theme.chalk.error(`${neon_js_1.neonSymbols.cross} No command specified`));
console.log('Usage: beeline run-plugin <command> [args...]');
return;
}
// Get all arguments after run-plugin
const pluginArgs = processArgs.slice(runPluginIndex + 1);
const commandName = pluginArgs[0];
if (!commandName) {
console.log(theme.chalk.error(`${neon_js_1.neonSymbols.cross} No command specified`));
console.log('Usage: beeline run-plugin <command> [args...]');
return;
}
// Parse arguments and flags manually
const remainingArgs = pluginArgs.slice(1);
const args = [];
const flags = {};
for (let i = 0; i < remainingArgs.length; i++) {
const arg = remainingArgs[i];
if (arg.startsWith('--')) {
// Handle long flags like --mock or --from account
const flagName = arg.substring(2);
// Check if next argument is the flag value (not another flag)
const nextArg = remainingArgs[i + 1];
if (i + 1 < remainingArgs.length && !nextArg.startsWith('--')) {
// Flag with value: --from account
flags[flagName] = nextArg;
i++; // Skip the next argument since it's the flag value
}
else {
// Boolean flag: --mock
flags[flagName] = true;
}
}
else if (arg.startsWith('-')) {
// Handle short flags like -m
const flagName = arg.substring(1);
flags[flagName] = true;
}
else {
// Regular argument
args.push(arg);
}
}
try {
const pluginManager = (0, simple_plugins_js_1.getPluginManager)();
await pluginManager.initialize();
const commands = pluginManager.getCommands();
if (!commands.has(commandName)) {
console.log(theme.chalk.error(`${neon_js_1.neonSymbols.cross} Plugin command not found: ${commandName}`));
console.log('');
console.log('Available plugin commands:');
for (const [name, cmd] of commands.entries()) {
console.log(` ${theme.chalk.highlight(name)} - ${cmd.description} ${theme.chalk.info(`(${cmd.pluginName})`)}`);
}
return;
}
await pluginManager.executeCommand(commandName, args, flags);
}
catch (error) {
console.log(theme.chalk.error(`${neon_js_1.neonSymbols.cross} Plugin command failed: ${error instanceof Error ? error.message : 'Unknown error'}`));
}
}
}
RunPlugin.description = 'Run a plugin command';
RunPlugin.examples = [
`$ beeline run-plugin hello`,
`$ beeline run-plugin hello Alice`,
`$ beeline run-plugin list-accounts`,
`$ beeline run-plugin he-transfer alice 10 BEE --mock`,
`$ beeline run-plugin he-transfer alice 10 BEE "Payment" --from myaccount`
];
RunPlugin.strict = false; // Allow any number of args
RunPlugin.args = {
command: core_1.Args.string({
description: 'plugin command to run',
required: true
})
};
exports.default = RunPlugin;
//# sourceMappingURL=run-plugin.js.map