40 lines
1.0 KiB
JavaScript
40 lines
1.0 KiB
JavaScript
/**
|
|
* Pure argv helpers for hdms (no bare-crypto / hyperdrive) so brittle-node can test parsing.
|
|
*/
|
|
|
|
/**
|
|
* @param {string[]} rest argv slice after `hdms pair`
|
|
* @returns {{ ok: true, persist: boolean, inviteTok: string } | { ok: false, error: string }}
|
|
*/
|
|
export function parseHdmsPairArgv(rest) {
|
|
let persist = true
|
|
let inviteTok = null
|
|
for (const x of rest) {
|
|
if (x === '--persist') continue
|
|
if (x === '--no-persist') {
|
|
persist = false
|
|
continue
|
|
}
|
|
if (String(x).startsWith('-')) {
|
|
return { ok: false, error: 'hdms: unknown flag: ' + x }
|
|
}
|
|
if (inviteTok) {
|
|
return { ok: false, error: 'hdms: pair expects a single invite string' }
|
|
}
|
|
inviteTok = x
|
|
}
|
|
if (rest.includes('--persist') && rest.includes('--no-persist')) {
|
|
return {
|
|
ok: false,
|
|
error: 'hdms: pair: use only one of --persist and --no-persist'
|
|
}
|
|
}
|
|
if (!inviteTok) {
|
|
return {
|
|
ok: false,
|
|
error: 'hdms: Usage: hdms pair [--persist|--no-persist] <invite>'
|
|
}
|
|
}
|
|
return { ok: true, persist, inviteTok }
|
|
}
|