introducde more flexible pathing
This commit is contained in:
@ -4,9 +4,9 @@ import * as helpers from "./smartssh.classes.helpers";
|
||||
import {SshKey} from "./smartssh.classes.sshkey"
|
||||
|
||||
export class SshConfig {
|
||||
sshKeyArray:SshKey[];
|
||||
private _sshKeyArray:SshKey[];
|
||||
constructor(sshKeyArrayArg:SshKey[]){
|
||||
this.sshKeyArray = sshKeyArrayArg;
|
||||
this._sshKeyArray = sshKeyArrayArg;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -16,8 +16,8 @@ export class SshConfig {
|
||||
let done = plugins.q.defer();
|
||||
let configArray:configObject[] = [];
|
||||
let configString;
|
||||
for(let key in this.sshKeyArray){
|
||||
let sshKey = this.sshKeyArray[key];
|
||||
for(let key in this._sshKeyArray){
|
||||
let sshKey = this._sshKeyArray[key];
|
||||
if(sshKey.host){
|
||||
configString = "Host " + sshKey.host + "\n" +
|
||||
" HostName " + sshKey.host + "\n" +
|
||||
@ -40,7 +40,8 @@ export class SshConfig {
|
||||
read(dirPathArg){
|
||||
let done = plugins.q.defer();
|
||||
let configArray:configObject[];
|
||||
|
||||
plugins.smartfile.fs.toStringSync(plugins.path.join(dirPathArg,"config"));
|
||||
|
||||
return done.promise;
|
||||
}
|
||||
};
|
||||
|
@ -17,14 +17,17 @@ export class SshDir { // sshDir class -> NOT EXPORTED, ONLY FOR INTERNAL USE
|
||||
this._path = plugins.path.join(plugins.smartpath.get.home(),".ssh/");
|
||||
};
|
||||
}
|
||||
writeToDir(){ // syncs sshInstance to directory
|
||||
writeToDir(dirPathArg?:string){ // syncs sshInstance to directory
|
||||
let path = this._path;
|
||||
if(dirPathArg) path = dirPathArg;
|
||||
this._sshKeyArray.forEach((sshKeyArg) => {
|
||||
sshKeyArg.store(this._path);
|
||||
sshKeyArg.store(path);
|
||||
});
|
||||
this._sshConfig.store(this._path);
|
||||
this._sshConfig.store(path);
|
||||
};
|
||||
readFromDir(){ // syncs sshInstance from directory
|
||||
|
||||
readFromDir(dirPathArg?:string){ // syncs sshInstance from directory
|
||||
let path = this._path;
|
||||
if(dirPathArg) path = dirPathArg;
|
||||
}
|
||||
updateDirPath(dirPathArg:string){
|
||||
this._path = dirPathArg;
|
||||
|
@ -62,15 +62,15 @@ export class SshInstance {
|
||||
/**
|
||||
* write SshInstance to disk
|
||||
*/
|
||||
writeToDisk(){
|
||||
this._sync("to");
|
||||
writeToDisk(dirPathArg?:string){
|
||||
this._sync("to",dirPathArg);
|
||||
}
|
||||
|
||||
/**
|
||||
* read ab SshInstance from disk
|
||||
*/
|
||||
readFromDisk(){
|
||||
this._sync("from");
|
||||
readFromDisk(dirPathArg?:string){
|
||||
this._sync("from",dirPathArg);
|
||||
}
|
||||
|
||||
/* ===============================================================
|
||||
@ -91,11 +91,11 @@ export class SshInstance {
|
||||
/**
|
||||
* private method to sync SshInstance
|
||||
*/
|
||||
private _sync(directionArg:string){
|
||||
private _sync(directionArg:string,dirPathArg?:string){
|
||||
if(directionArg == "from"){
|
||||
this._sshDir.readFromDir(); // call sync method of sshDir class;
|
||||
this._sshDir.readFromDir(dirPathArg); // call sync method of sshDir class;
|
||||
} else if(directionArg == "to") {
|
||||
this._sshDir.writeToDir();
|
||||
this._sshDir.writeToDir(dirPathArg);
|
||||
} else {
|
||||
throw new Error("directionArg not recognised. Must be 'to' or 'from'");
|
||||
}
|
||||
|
Reference in New Issue
Block a user