remindctl/Sources/remindctl/Commands/CompleteCommand.swift
Peter Steinberger 883ae25791
Some checks failed
CI / build (push) Has been cancelled
fix: resolve reminder indexes from show view
2026-05-08 15:13:00 +01:00

47 lines
1.4 KiB
Swift

import Commander
import Foundation
import RemindCore
enum CompleteCommand {
static var spec: CommandSpec {
CommandSpec(
name: "complete",
abstract: "Mark reminders complete",
discussion: "Use indexes or ID prefixes from show output.",
signature: CommandSignatures.withRuntimeFlags(
CommandSignature(
arguments: [
.make(label: "ids", help: "Indexes or ID prefixes", isOptional: true)
],
flags: [
.make(label: "dryRun", names: [.short("n"), .long("dry-run")], help: "Preview without changes")
]
)
),
usageExamples: [
"remindctl complete 1",
"remindctl complete 1 2 3",
"remindctl complete 4A83",
]
) { values, runtime in
let inputs = values.positional
guard !inputs.isEmpty else {
throw ParsedValuesError.missingArgument("ids")
}
let store = RemindersStore()
try await store.requestAccess()
let reminders = try await store.reminders(in: nil)
let resolved = try CommandHelpers.resolveShowIdentifiers(inputs, from: reminders)
if values.flag("dryRun") {
OutputRenderer.printReminders(resolved, format: runtime.outputFormat)
return
}
let updated = try await store.completeReminders(ids: resolved.map { $0.id })
OutputRenderer.printReminders(updated, format: runtime.outputFormat)
}
}
}