From 339aff435b9189fec1c82115c769deca56406cbc Mon Sep 17 00:00:00 2001 From: Siddharth Singh Date: Mon, 30 Sep 2024 11:37:55 +0530 Subject: [PATCH] log commands as they are executed, dispose of ssh when done --- tribes-cli/utils/ssh/mod.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tribes-cli/utils/ssh/mod.ts b/tribes-cli/utils/ssh/mod.ts index 9f7f9667..f88ed655 100644 --- a/tribes-cli/utils/ssh/mod.ts +++ b/tribes-cli/utils/ssh/mod.ts @@ -37,11 +37,11 @@ class TribesClient { * @returns The standard output of the command. */ async do(name: K, ...args: Parameters) { - const cmd = commands[name]; // @ts-ignore this is okay because typescript enforces the correct args at the callsite - const res = await this.ssh.execCommand(cmd(...args)); + const cmd = commands[name](...args); + console.log(`=> ${cmd}`); + const res = await this.ssh.execCommand(cmd); if (res.code) throw new Error(`Error executing ${name}: ${res.stderr}`); - console.error(res); return res.stdout; } /** @@ -54,6 +54,9 @@ class TribesClient { const stdout = await this.do(name, ...args); console.log(stdout); } + async disconnect() { + this.ssh.dispose(); + } } interface HandlerOptions { @@ -68,7 +71,9 @@ export const makeSshAction = (handler: (opts: HandlerOptions) => Promise | const arg = (name: string) => args[name] as string; const domain = args._[0] as string; const tribes = await connect(domain, arg('identity-file')); - handler({ args, arg, tribes, domain }); + await handler({ args, arg, tribes, domain }); + console.log('Done.'); + tribes.disconnect(); }; };