MCPcopy Create free account
hub / github.com/electric-sql/electric / parseArgs

Function parseArgs

packages/start/src/cli.ts:16–70  ·  view source on GitHub ↗
(args: string[])

Source from the content-addressed store, hash-verified

14}
15
16function parseArgs(args: string[]): ParsedArgs {
17 const positionalArgs: string[] = []
18 let sourceId: string | undefined
19 let secret: string | undefined
20 let databaseUrl: string | undefined
21
22 for (let i = 0; i < args.length; i++) {
23 if (args[i] === `--source`) {
24 sourceId = args[i + 1]
25 if (!sourceId || sourceId.startsWith(`-`)) {
26 console.error(`Error: --source requires a source ID value`)
27 process.exit(1)
28 }
29 i++ // Skip the value
30 } else if (args[i] === `--secret`) {
31 secret = args[i + 1]
32 if (!secret || secret.startsWith(`-`)) {
33 console.error(`Error: --secret requires a value`)
34 process.exit(1)
35 }
36 i++ // Skip the value
37 } else if (args[i] === `--database-url`) {
38 databaseUrl = args[i + 1]
39 if (!databaseUrl || databaseUrl.startsWith(`-`)) {
40 console.error(`Error: --database-url requires a value`)
41 process.exit(1)
42 }
43 i++ // Skip the value
44 } else if (!args[i].startsWith(`-`)) {
45 positionalArgs.push(args[i])
46 }
47 }
48
49 if (positionalArgs.length === 0) {
50 console.error(
51 `Usage: npx @electric-sql/start <app-name> [--source <source-id>] [--secret <secret>] [--database-url <url>]`
52 )
53 console.error(
54 ` npx @electric-sql/start . (configure current directory)`
55 )
56 process.exit(1)
57 }
58
59 if (positionalArgs.length > 1) {
60 console.error(
61 `Error: Expected only one app name, but received multiple: ${positionalArgs.join(`, `)}`
62 )
63 console.error(
64 `Usage: npx @electric-sql/start <app-name> [--source <source-id>] [--secret <secret>] [--database-url <url>]`
65 )
66 process.exit(1)
67 }
68
69 return { appName: positionalArgs[0], sourceId, secret, databaseUrl }
70}
71
72function prompt(question: string): Promise<string> {
73 const rl = createInterface({

Callers 1

mainFunction · 0.70

Calls 3

errorMethod · 0.45
pushMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected