UNPKG

@cliz/cp

Version:

Online pbcopy + pbpaste

53 lines (52 loc) 1.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const cli_1 = require("@cliz/cli"); const core_1 = require("../core"); exports.default = (0, cli_1.defineSubCommand)(createCommand => { return createCommand('Pbpaste online') .argument('code', 'Pbpaste code') .option('-r, --relay <relay>', 'Use custom relay') .action(async ({ args, options }) => { let code = args.code; if (!code) { const answers = await cli_1.inquirer.prompt([ { type: 'input', name: '_code', message: 'Enter pbzopy code:', validate(value) { if (!value) { return 'code is required'; } return true; }, }, ]); code = answers._code; } const _options = { ...args, ...options, code, }; try { const data = await (0, core_1.paste)(_options); try { await cli_1.api.clipboard.copy(data); console.info('Copied the paste to clipboard, just use Ctrl + V use it.'); } catch (error) { console.error([ '--- Pbzopy Start ---', data, '--- Pbzopy End ---', '', 'Copy the paste error, please copy yourself', ].join('\n')); } } catch (error) { console.error(error); } }); });