(
id: string,
opts: TaskUpdateOptions = {},
)
| 813 | } |
| 814 | |
| 815 | export async function taskUpdateHandler( |
| 816 | id: string, |
| 817 | opts: TaskUpdateOptions = {}, |
| 818 | ): Promise<void> { |
| 819 | try { |
| 820 | if (opts.clearOwner && opts.owner) { |
| 821 | throw new Error('Use either --owner or --clear-owner, not both.') |
| 822 | } |
| 823 | if (opts.status && !TASK_STATUSES.includes(opts.status as Task['status'])) { |
| 824 | throw new Error( |
| 825 | `Invalid status "${opts.status}". Expected one of: ${TASK_STATUSES.join(', ')}.`, |
| 826 | ) |
| 827 | } |
| 828 | |
| 829 | const updates: Partial<Omit<Task, 'id'>> = {} |
| 830 | if (typeof opts.status !== 'undefined') { |
| 831 | updates.status = opts.status as Task['status'] |
| 832 | } |
| 833 | if (typeof opts.subject !== 'undefined') { |
| 834 | updates.subject = opts.subject |
| 835 | } |
| 836 | if (typeof opts.description !== 'undefined') { |
| 837 | updates.description = opts.description |
| 838 | } |
| 839 | if (typeof opts.owner !== 'undefined') { |
| 840 | updates.owner = opts.owner |
| 841 | } |
| 842 | if (opts.clearOwner) { |
| 843 | updates.owner = undefined |
| 844 | } |
| 845 | |
| 846 | if (Object.keys(updates).length === 0) { |
| 847 | throw new Error('No updates were specified.') |
| 848 | } |
| 849 | |
| 850 | const taskListId = normalizeTaskListId(opts.list) |
| 851 | const task = await updateTask(taskListId, id, updates) |
| 852 | if (!task) { |
| 853 | throw new Error(`Task ${id} was not found in ${taskListId}.`) |
| 854 | } |
| 855 | |
| 856 | writeJson({ |
| 857 | taskListId, |
| 858 | task, |
| 859 | }) |
| 860 | await gracefulShutdown(0) |
| 861 | } catch (error) { |
| 862 | writeToStderr(`Failed to update task: ${errorMessage(error)}\n`) |
| 863 | await gracefulShutdown(1) |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | export async function taskDirHandler( |
| 868 | opts: TaskListOptions = {}, |
no test coverage detected