Skip to content

Commit

Permalink
Command to list known peer IDs #8
Browse files Browse the repository at this point in the history
  • Loading branch information
caolan committed Oct 7, 2024
1 parent 74781e1 commit 9f3afb7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
9 changes: 9 additions & 0 deletions mutiny/src/commands/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 <SOCKET> Unix socket to bind to");
console.error(" --help Show this message");
break;
}
default: {
console.error("Usage: mutiny COMMAND");
console.error("");
Expand Down
17 changes: 17 additions & 0 deletions mutiny/src/commands/peers.ts
Original file line number Diff line number Diff line change
@@ -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<typeof parseArgs>) {
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);
}
}
5 changes: 5 additions & 0 deletions mutiny/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -24,6 +25,10 @@ if (import.meta.main) {
dial(args);
break;
}
case "peers": {
peers(args);
break;
}
default: {
console.error(`Unknown command: ${command}`);
console.error("");
Expand Down

0 comments on commit 9f3afb7

Please sign in to comment.