-
Notifications
You must be signed in to change notification settings - Fork 2
/
list.ts
44 lines (39 loc) · 1.5 KB
/
list.ts
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
import { Flags, ux } from "@oclif/core";
import { BaseCommand } from "../../base-command.js";
import { EOL } from "os";
import { getPlebbitLogger } from "../../../util.js";
export default class List extends BaseCommand {
static override description = "List your subplebbits";
static override examples = [];
static override flags = {
quiet: Flags.boolean({ char: "q", summary: "Only display subplebbit addresses" }),
...ux.table.flags()
};
async run(): Promise<void> {
const { flags } = await this.parse(List);
const log = (await getPlebbitLogger())("plebbit-cli:commands:subplebbit:list");
log(`flags: `, flags);
const plebbit = await this._connectToPlebbitRpc(flags.plebbitRpcUrl.toString());
const subs = plebbit.subplebbits;
if (flags.quiet) {
this.log(subs.join(EOL));
} else {
const subsWithStarted = await Promise.all(
subs.map(async (subAddress) => {
const subInstance = await plebbit.createSubplebbit({ address: subAddress });
return { address: subInstance.address, started: subInstance.started };
})
);
ux.table(
subsWithStarted,
{ address: {}, started: {} },
{
printLine: this.log.bind(this),
...flags,
sort: "-started"
}
);
}
await plebbit.destroy();
}
}