Files
orca/src/shared/cli-argument-boundary.ts
T
OrcaWinandm4air 47ddfbdc0d feat: let users choose JSON or SQLite when profile copies diverge (#23278)
Replace the copy-a-command startup dialog for diverged JSON/SQLite profile
state with Use SQLite / Use JSON buttons. The choice relaunches Orca into the
locked recovery preflight, applies it, then starts normally. Adds a
current-sqlite recovery selector (and --current-sqlite CLI flag) that archives
the diverged JSON and republishes it from SQLite.

Co-authored-by: m4air <m4air@m4airs-Air.localdomain>
2026-09-26 17:03:05 -07:00

105 lines
2.3 KiB
TypeScript

export const CLI_GLOBAL_VALUE_FLAGS: readonly string[] = ['pairing-code', 'environment']
export const CLI_GLOBAL_FLAGS: readonly string[] = ['help', 'json', ...CLI_GLOBAL_VALUE_FLAGS]
export const CLI_BOOLEAN_FLAGS = new Set([
'all',
'allow-failed-archive-hook',
'attachments',
'children',
'comments',
'connect',
'current',
'current-json',
'current-sqlite',
'debug',
'dry-run',
'enter',
'focus',
'force',
'fresh',
'full',
'help',
'inject',
'include-archived',
'include-remote',
'include-visual-layouts',
'index-status',
'interrupt',
'json',
'local',
'messages',
'me',
'mobile',
'mobile-pairing',
'no-pairing',
'screen',
'parent-current',
'provision',
'ready',
'recipe-json',
'references',
'relations',
'reinstall',
'restore-window',
'return-preamble',
'run-hooks',
'show-profile',
'staged',
'tab',
'tasks',
'text-stdin',
'unread',
'value-stdin',
'wait'
])
function commandPathStartsAt(
argv: readonly string[],
tokenIndex: number,
path: readonly string[]
): boolean {
let cursor = tokenIndex
for (const part of path) {
while (argv[cursor]?.startsWith('--')) {
const assignment = argv[cursor].slice(2)
const flag = assignment.split('=', 1)[0]
cursor += assignment.includes('=') || CLI_BOOLEAN_FLAGS.has(flag) ? 1 : 2
}
if (argv[cursor] !== part) {
return false
}
cursor += 1
}
return true
}
export function findCliCommandIndex(
argv: readonly string[],
commandPaths: readonly (readonly string[])[],
knownValueFlags: readonly string[] = []
): number {
const startsCommandAt = (index: number): boolean =>
commandPaths.some((path) => commandPathStartsAt(argv, index, path))
for (let index = 0; index < argv.length;) {
const token = argv[index]
if (!token.startsWith('--')) {
return startsCommandAt(index) ? index : -1
}
const assignment = token.slice(2)
const flag = assignment.split('=', 1)[0]
const next = argv[index + 1]
const takesNext =
!assignment.includes('=') &&
!CLI_BOOLEAN_FLAGS.has(flag) &&
next !== undefined &&
!next.startsWith('--') &&
(knownValueFlags.includes(flag) ||
!(startsCommandAt(index + 1) && !startsCommandAt(index + 2)))
index += takesNext ? 2 : 1
}
return -1
}