From 9f3afb7684ea9a9803a97635dcb1e0c90a8491d3 Mon Sep 17 00:00:00 2001 From: Caolan McMahon Date: Mon, 7 Oct 2024 11:30:28 +0100 Subject: [PATCH] Command to list known peer IDs #8 --- mutiny/src/commands/help.ts | 9 +++++++++ mutiny/src/commands/peers.ts | 17 +++++++++++++++++ mutiny/src/main.ts | 5 +++++ 3 files changed, 31 insertions(+) create mode 100644 mutiny/src/commands/peers.ts diff --git a/mutiny/src/commands/help.ts b/mutiny/src/commands/help.ts index 730a2a1..7f3e45c 100644 --- a/mutiny/src/commands/help.ts +++ b/mutiny/src/commands/help.ts @@ -3,6 +3,7 @@ export function listCommands() { console.error(" serve Serve an application"); console.error(" info Show info about mutinyd"); console.error(" dial Connects to a known multi-address"); + console.error(" peers List known peer IDs"); } export function help(command?: string) { @@ -38,6 +39,14 @@ export function help(command?: string) { console.error(" --help Show this message"); break; } + case "peers": { + console.error("Usage: mutiny peers [OPTIONS]"); + console.error(""); + console.error("Options:"); + console.error(" -s, --socket Unix socket to bind to"); + console.error(" --help Show this message"); + break; + } default: { console.error("Usage: mutiny COMMAND"); console.error(""); diff --git a/mutiny/src/commands/peers.ts b/mutiny/src/commands/peers.ts new file mode 100644 index 0000000..d0cba40 --- /dev/null +++ b/mutiny/src/commands/peers.ts @@ -0,0 +1,17 @@ +import { defaultSocketPath } from "../client.ts"; +import { parseArgs } from "@std/cli/parse-args"; +import { help } from "./help.ts"; +import { MutinyClient } from "../client.ts"; + +export default async function (args: ReturnType) { + if (args.help) { + help('peers'); + } + const socket_path = args.s || args.socket || defaultSocketPath(); + + const client = new MutinyClient({socket_path}); + const peers = await client.peers(); + for (const peer of peers) { + console.log(peer); + } +} diff --git a/mutiny/src/main.ts b/mutiny/src/main.ts index 8d7ade5..b20c207 100644 --- a/mutiny/src/main.ts +++ b/mutiny/src/main.ts @@ -3,6 +3,7 @@ import { parseArgs } from "@std/cli/parse-args"; import serve from "./commands/serve.ts"; import info from "./commands/info.ts"; import dial from "./commands/dial.ts"; +import peers from "./commands/peers.ts"; if (import.meta.main) { const args = parseArgs(Deno.args); @@ -24,6 +25,10 @@ if (import.meta.main) { dial(args); break; } + case "peers": { + peers(args); + break; + } default: { console.error(`Unknown command: ${command}`); console.error("");