@controlplane/cli
Version:
Control Plane Corporation CLI
72 lines • 2.61 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PortForwardCmd = void 0;
const command_1 = require("../cli/command");
const functions_1 = require("../util/functions");
const options_1 = require("./options");
const generic_1 = require("./generic");
const port_forwarder_1 = require("../portforward/port-forwarder");
// SECTION - Functions
function withWorkload(yargs) {
return yargs.positional('ref', {
type: 'string',
describe: 'The name of the workload to forward traffic to.',
demandOption: true,
});
}
function withPorts(yargs) {
return yargs.positional('ports', {
type: 'string',
describe: 'Port mappings in the format [LOCAL_PORT:]REMOTE_PORT (e.g. 8080:80).',
array: true,
demandOption: true,
});
}
function withPortForwardOptions(yargs) {
return yargs.options({
address: {
requiresArg: true,
description: 'Addresses to listen on (comma separated). Only accepts IP addresses or localhost as a value. When localhost is supplied, cpln will try to bind on both 127.0.0.1 and ::1 and will fail if neither of these addresses are available to bind.',
default: 'localhost',
},
replica: {
requiresArg: true,
description: 'The name of the workload deployment replica',
},
});
}
// !SECTION
// ANCHOR - Command
class PortForwardCmd extends command_1.Command {
constructor() {
super(...arguments);
this.command = 'port-forward <ref> <ports...>';
this.describe = 'Forward one or more local ports to a workload';
}
// Public Methods //
builder(yargs) {
return (0, functions_1.pipe)(
//
withWorkload, withPorts, (0, generic_1.withSingleLocationOption)(false), withPortForwardOptions, options_1.withAllOptions)(yargs);
}
async handle(args) {
// Split the comma-separated address option into individual addresses
const addresses = args.address.split(',');
// Run the shared port-forward engine in-process
const forwarder = new port_forwarder_1.PortForwarder(this.client, this.session);
try {
await forwarder.start({
workload: args.ref,
ports: args.ports,
addresses,
location: args.location,
replica: args.replica,
});
}
catch (e) {
this.session.abort({ error: e });
}
}
}
exports.PortForwardCmd = PortForwardCmd;
//# sourceMappingURL=portforward.js.map