UNPKG

msbot

Version:

MSBot command line tool for manipulating Microsoft Bot Framework .bot files

69 lines 2.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * Copyright(c) Microsoft Corporation.All rights reserved. * Licensed under the MIT License. */ // tslint:disable:no-console // tslint:disable:no-object-literal-type-assertion const botframework_config_1 = require("botframework-config"); const chalk = require("chalk"); const program = require("commander"); const stdioAsync_1 = require("./stdioAsync"); program.Command.prototype.unknownOption = (flag) => { console.error(chalk.default.redBright(`Unknown arguments: ${flag}`)); showErrorHelp(); }; program .name('msbot disconnect') .arguments('<service_id_or_Name>') .description('disconnect a connected service by id or name') .option('-b, --bot <path>', 'path to bot file. If omitted, local folder will look for a .bot file') .option('--secret <secret>', 'bot file secret password for encrypting service secrets') .option('--prefix', 'Append [msbot] prefix to all messages') .action((idOrName, actions) => { actions.idOrName = idOrName; }); const command = program.parse(process.argv); const args = {}; Object.assign(args, command); if (process.argv.length < 3) { program.help(); } else { if (!args.bot) { botframework_config_1.BotConfiguration.loadBotFromFolder(process.cwd(), args.secret) .then(processDisconnectArgs) .catch((reason) => { console.error(chalk.default.redBright(reason.toString().split('\n')[0])); showErrorHelp(); }); } else { botframework_config_1.BotConfiguration.load(args.bot, args.secret) .then(processDisconnectArgs) .catch((reason) => { console.error(chalk.default.redBright(reason.toString().split('\n')[0])); showErrorHelp(); }); } } async function processDisconnectArgs(config) { if (!args.idOrName) { throw new Error('missing id or name of service to disconnect'); } const removedService = config.disconnectServiceByNameOrId(args.idOrName); if (removedService != null) { await config.save(args.secret); await stdioAsync_1.stdoutAsync(`Disconnected ${removedService.type}:${removedService.name} ${removedService.id}`); } return config; } function showErrorHelp() { program.outputHelp((str) => { console.error(str); return ''; }); process.exit(1); } //# sourceMappingURL=msbot-disconnect.js.map