mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
log commands as they are executed, dispose of ssh when done
This commit is contained in:
parent
5cbdf30501
commit
339aff435b
1 changed files with 9 additions and 4 deletions
|
|
@ -37,11 +37,11 @@ class TribesClient {
|
||||||
* @returns The standard output of the command.
|
* @returns The standard output of the command.
|
||||||
*/
|
*/
|
||||||
async do<K extends keyof typeof commands>(name: K, ...args: Parameters<typeof commands[K]>) {
|
async do<K extends keyof typeof commands>(name: K, ...args: Parameters<typeof commands[K]>) {
|
||||||
const cmd = commands[name];
|
|
||||||
// @ts-ignore this is okay because typescript enforces the correct args at the callsite
|
// @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}`);
|
if (res.code) throw new Error(`Error executing ${name}: ${res.stderr}`);
|
||||||
console.error(res);
|
|
||||||
return res.stdout;
|
return res.stdout;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
@ -54,6 +54,9 @@ class TribesClient {
|
||||||
const stdout = await this.do(name, ...args);
|
const stdout = await this.do(name, ...args);
|
||||||
console.log(stdout);
|
console.log(stdout);
|
||||||
}
|
}
|
||||||
|
async disconnect() {
|
||||||
|
this.ssh.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface HandlerOptions {
|
interface HandlerOptions {
|
||||||
|
|
@ -68,7 +71,9 @@ export const makeSshAction = (handler: (opts: HandlerOptions) => Promise<void> |
|
||||||
const arg = (name: string) => args[name] as string;
|
const arg = (name: string) => args[name] as string;
|
||||||
const domain = args._[0] as string;
|
const domain = args._[0] as string;
|
||||||
const tribes = await connect(domain, arg('identity-file'));
|
const tribes = await connect(domain, arg('identity-file'));
|
||||||
handler({ args, arg, tribes, domain });
|
await handler({ args, arg, tribes, domain });
|
||||||
|
console.log('Done.');
|
||||||
|
tribes.disconnect();
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue