-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstop.ts
More file actions
50 lines (43 loc) · 1.81 KB
/
stop.ts
File metadata and controls
50 lines (43 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { PKCLogger } from "../../../util.js";
import { BaseCommand } from "../../base-command.js";
import { Args } from "@oclif/core";
export default class Stop extends BaseCommand {
static override description =
"Stop a community. The community will not publish or receive any publications until it is started again.";
static override strict = false; // To allow for variable length arguments
static override args = {
addresses: Args.string({
name: "addresses",
required: true,
description: "Addresses of communities to stop. Separated by space"
})
};
static override examples = [
"bitsocial community stop plebbit.bso",
"bitsocial community stop Qmb99crTbSUfKXamXwZBe829Vf6w5w5TktPkb6WstC9RFW"
];
async run() {
const { argv, flags } = await this.parse(Stop);
const log = PKCLogger("bitsocial-cli:commands:community:stop");
log(`addresses: `, argv);
log(`flags: `, flags);
const addresses = <string[]>argv;
if (!Array.isArray(addresses)) this.error(`Failed to parse addresses correctly (${addresses})`);
const pkc = await this._connectToPkcRpc(flags.pkcRpcUrl.toString());
for (const address of addresses) {
try {
const community = await pkc.createCommunity({ address });
await community.stop();
this.log(address);
} catch (e) {
const error = e instanceof Error ? e : new Error(typeof e === "string" ? e : JSON.stringify(e));
//@ts-expect-error
error.details = { ...error.details, address };
console.error(error);
await pkc.destroy();
this.exit(1);
}
}
await pkc.destroy();
}
}