@eightshone/sshman
Version:
A simple cli ssh manager
55 lines • 2.73 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import findServer from "../../utils/findServer.js";
import isConnectionString from "../../utils/isConnectionString.js";
import parseConnectionString from "../../utils/parseConnectionString.js";
import updateConfigs from "../../utils/updateConfigs.js";
import validateServerName from "../../utils/validateServerName.js";
import init from "../functions/init.js";
import sshConnection from "../functions/ssh.js";
function connectCommand(creds, options) {
return __awaiter(this, void 0, void 0, function* () {
// intialize the cli app
let { config, logs } = yield init();
// save connection may contains the server name
const saveConnection = options.save;
let sshConfig;
const newConnection = isConnectionString(creds);
if (newConnection) {
sshConfig = parseConnectionString(creds);
if (!!saveConnection &&
typeof saveConnection === "string" &&
!!(saveConnection === null || saveConnection === void 0 ? void 0 : saveConnection.length)) {
const isValid = validateServerName(saveConnection, config.servers);
if (isValid === true) {
sshConfig.name = saveConnection;
}
else {
console.log(`❌ ${isValid}`);
return;
}
}
else if (!!saveConnection && typeof saveConnection === "boolean") {
console.log(`ℹ️ You did not specify a name for this config! It will be saved under the name: ${sshConfig.name}`);
}
}
else {
sshConfig = findServer(config.servers, creds);
if (!sshConfig) {
console.log("❌ Server config not found!");
return;
}
}
[config, logs] = yield updateConfigs(config, logs, sshConfig, !!saveConnection && newConnection);
sshConnection(sshConfig);
});
}
export default connectCommand;
//# sourceMappingURL=connect.js.map