mirror of
https://github.com/stablyai/orca.git
synced 2026-10-13 08:02:52 +00:00
88 lines
3.5 KiB
TypeScript
88 lines
3.5 KiB
TypeScript
import type {
|
|
RuntimeWorktreeListResult,
|
|
RuntimeWorktreePsResult,
|
|
RuntimeWorktreeRecord
|
|
} from '../../shared/runtime-types'
|
|
import type { CommandHandler } from '../dispatch'
|
|
import { formatWorktreeList, formatWorktreePs, formatWorktreeShow, printResult } from '../format'
|
|
import {
|
|
getOptionalNullableNumberFlag,
|
|
getOptionalNumberFlag,
|
|
getOptionalPositiveIntegerFlag,
|
|
getOptionalStringFlag,
|
|
getRequiredStringFlag
|
|
} from '../flags'
|
|
import { getRequiredWorktreeSelector, resolveCurrentWorktreeSelector } from '../selectors'
|
|
|
|
type HookWarningResult = {
|
|
warning?: string
|
|
}
|
|
|
|
function printHookWarning(result: HookWarningResult, json: boolean): void {
|
|
if (!json && result.warning) {
|
|
console.error(`warning: ${result.warning}`)
|
|
}
|
|
}
|
|
|
|
export const WORKTREE_HANDLERS: Record<string, CommandHandler> = {
|
|
'worktree ps': async ({ flags, client, json }) => {
|
|
const result = await client.call<RuntimeWorktreePsResult>('worktree.ps', {
|
|
limit: getOptionalPositiveIntegerFlag(flags, 'limit')
|
|
})
|
|
printResult(result, json, formatWorktreePs)
|
|
},
|
|
'worktree list': async ({ flags, client, json }) => {
|
|
const result = await client.call<RuntimeWorktreeListResult>('worktree.list', {
|
|
repo: getOptionalStringFlag(flags, 'repo'),
|
|
limit: getOptionalPositiveIntegerFlag(flags, 'limit')
|
|
})
|
|
printResult(result, json, formatWorktreeList)
|
|
},
|
|
'worktree show': async ({ flags, client, cwd, json }) => {
|
|
const result = await client.call<{ worktree: RuntimeWorktreeRecord }>('worktree.show', {
|
|
worktree: await getRequiredWorktreeSelector(flags, 'worktree', cwd, client)
|
|
})
|
|
printResult(result, json, formatWorktreeShow)
|
|
},
|
|
'worktree current': async ({ client, cwd, json }) => {
|
|
const result = await client.call<{ worktree: RuntimeWorktreeRecord }>('worktree.show', {
|
|
worktree: await resolveCurrentWorktreeSelector(cwd, client)
|
|
})
|
|
printResult(result, json, formatWorktreeShow)
|
|
},
|
|
'worktree create': async ({ flags, client, json }) => {
|
|
const result = await client.call<{ worktree: RuntimeWorktreeRecord; warning?: string }>(
|
|
'worktree.create',
|
|
{
|
|
repo: getRequiredStringFlag(flags, 'repo'),
|
|
name: getRequiredStringFlag(flags, 'name'),
|
|
baseBranch: getOptionalStringFlag(flags, 'base-branch'),
|
|
linkedIssue: getOptionalNumberFlag(flags, 'issue'),
|
|
comment: getOptionalStringFlag(flags, 'comment'),
|
|
runHooks: flags.get('run-hooks') === true,
|
|
activate: flags.get('activate') === true || flags.get('run-hooks') === true
|
|
}
|
|
)
|
|
printHookWarning(result.result, json)
|
|
printResult(result, json, formatWorktreeShow)
|
|
},
|
|
'worktree set': async ({ flags, client, cwd, json }) => {
|
|
const result = await client.call<{ worktree: RuntimeWorktreeRecord }>('worktree.set', {
|
|
worktree: await getRequiredWorktreeSelector(flags, 'worktree', cwd, client),
|
|
displayName: getOptionalStringFlag(flags, 'display-name'),
|
|
linkedIssue: getOptionalNullableNumberFlag(flags, 'issue'),
|
|
comment: getOptionalStringFlag(flags, 'comment')
|
|
})
|
|
printResult(result, json, formatWorktreeShow)
|
|
},
|
|
'worktree rm': async ({ flags, client, cwd, json }) => {
|
|
const result = await client.call<{ removed: boolean; warning?: string }>('worktree.rm', {
|
|
worktree: await getRequiredWorktreeSelector(flags, 'worktree', cwd, client),
|
|
force: flags.get('force') === true,
|
|
runHooks: flags.get('run-hooks') === true
|
|
})
|
|
printHookWarning(result.result, json)
|
|
printResult(result, json, (value) => `removed: ${value.removed}`)
|
|
}
|
|
}
|