forked from
slices.network/slices
Highly ambitious ATProtocol AppView service and sdks
1import { pushCommand } from "./lexicon/push.ts";
2import { pullCommand } from "./lexicon/pull.ts";
3import { listCommand } from "./lexicon/list.ts";
4
5function showLexiconHelp() {
6 console.log(`
7slices lexicon - Manage lexicons
8
9USAGE:
10 slices lexicon <SUBCOMMAND> [OPTIONS]
11
12SUBCOMMANDS:
13 push Push lexicon files to your slice
14 pull Pull lexicon files from your slice
15 list List lexicons in your slice
16 help Show this help message
17
18OPTIONS:
19 -h, --help Show help information
20
21EXAMPLES:
22 slices lexicon push --slice at://did:plc:example/slice
23 slices lexicon pull --slice at://did:plc:example/slice
24 slices lexicon list --slice at://did:plc:example/slice
25 slices lexicon help
26`);
27}
28
29export async function lexiconCommand(
30 commandArgs: unknown[],
31 globalArgs: Record<string, unknown>
32): Promise<void> {
33 // Use the same pattern as main CLI - find subcommand in raw args
34 const rawArgs = commandArgs as string[];
35
36 if (rawArgs.length === 0) {
37 showLexiconHelp();
38 return;
39 }
40
41 // If the first arg is help or --help, show lexicon help
42 if (
43 rawArgs[0] === "help" ||
44 (rawArgs.length === 1 && (rawArgs[0] === "--help" || rawArgs[0] === "-h"))
45 ) {
46 showLexiconHelp();
47 return;
48 }
49
50 const subcommand = rawArgs[0];
51
52 // Find the subcommand index and pass everything after it
53 const subcommandIndex = rawArgs.findIndex((arg) => arg === subcommand);
54 const subcommandArgs =
55 subcommandIndex >= 0 ? rawArgs.slice(subcommandIndex + 1) : [];
56
57 try {
58 switch (subcommand) {
59 case "push":
60 await pushCommand(subcommandArgs, globalArgs);
61 break;
62 case "pull":
63 await pullCommand(subcommandArgs, globalArgs);
64 break;
65 case "list":
66 await listCommand(subcommandArgs, globalArgs);
67 break;
68 case "help":
69 showLexiconHelp();
70 break;
71 default:
72 console.error(`Unknown lexicon subcommand: ${subcommand}`);
73 console.error("Run 'slices lexicon help' for usage information.");
74 Deno.exit(1);
75 }
76 } catch (error) {
77 const err = error as Error;
78 console.error(`Lexicon command failed: ${err.message}`);
79 Deno.exit(1);
80 }
81}