Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions Sources/remindctl/CommandHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,6 @@ enum CommandHelpers {
return nil
}

static func requiredListTarget(
name: String?,
id: String?,
argumentName: String = "list"
) throws -> ReminderListTarget {
guard let target = try listTarget(name: name, id: id) else {
throw ParsedValuesError.missingArgument(argumentName)
}
return target
}

static func reminder(_ reminder: ReminderItem, matchesSearch query: String) -> Bool {
let trimmed = query.trimmingCharacters(in: .whitespacesAndNewlines)
guard !trimmed.isEmpty else { return false }
Expand Down
36 changes: 19 additions & 17 deletions Sources/remindctl/CommandRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,27 @@ struct CommandRouter {
let specs: [CommandSpec]
let program: Program

static let commandSpecs: [CommandSpec] = [
ShowCommand.spec,
ListCommand.spec,
SearchCommand.spec,
InfoCommand.spec,
AddCommand.spec,
EditCommand.spec,
CompleteCommand.spec,
DeleteCommand.spec,
StatusCommand.spec,
AuthorizeCommand.spec,
DoctorCommand.spec,
ExportCommand.spec,
LinkCommand.spec,
OpenCommand.spec,
CompletionCommand.spec,
]

init() {
self.version = CommandRouter.resolveVersion()
self.specs = [
ShowCommand.spec,
ListCommand.spec,
SearchCommand.spec,
InfoCommand.spec,
AddCommand.spec,
EditCommand.spec,
CompleteCommand.spec,
DeleteCommand.spec,
StatusCommand.spec,
AuthorizeCommand.spec,
DoctorCommand.spec,
ExportCommand.spec,
LinkCommand.spec,
OpenCommand.spec,
CompletionCommand.spec,
]
self.specs = Self.commandSpecs
let descriptor = CommandDescriptor(
name: rootName,
abstract: "Manage Apple Reminders from the terminal",
Expand Down
4 changes: 2 additions & 2 deletions Sources/remindctl/CommandSpec.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Commander

struct CommandSpec: @unchecked Sendable {
struct CommandSpec: Sendable {
let name: String
let abstract: String
let discussion: String?
let signature: CommandSignature
let usageExamples: [String]
let run: (ParsedValues, RuntimeOptions) async throws -> Void
let run: @Sendable (ParsedValues, RuntimeOptions) async throws -> Void

var descriptor: CommandDescriptor {
CommandDescriptor(
Expand Down
3 changes: 1 addition & 2 deletions Sources/remindctl/Commands/AddCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,12 @@ enum AddCommand {
radius: String?,
leaving: Bool
) throws -> LocationTrigger? {
if location == nil {
guard let location else {
if radius != nil || leaving {
throw RemindCoreError.operationFailed("Use --location with --radius or --leaving")
}
return nil
}
guard let location else { return nil }
let radius = try radius.map(parseRadius) ?? 100
return LocationTrigger(
address: location,
Expand Down
7 changes: 3 additions & 4 deletions Sources/remindctl/Commands/CompletionCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ enum CompletionCommand {
}
}

private static let commands = [
"show", "list", "search", "info", "add", "edit", "complete", "delete", "status", "authorize", "doctor", "export",
"link", "open", "completion",
]
private static var commands: [String] {
CommandRouter.commandSpecs.map(\.name)
}

private static func zsh() -> String {
"""
Expand Down
12 changes: 2 additions & 10 deletions Sources/remindctl/Commands/OpenCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,8 @@ enum OpenCommand {
}

let url: URL
if values.flag("app") {
if values.argument(0) != nil || listTarget != nil {
let result = try await LinkCommand.resolve(values: values)
guard let parsed = URL(string: result.url) else {
throw RemindCoreError.operationFailed("Invalid Reminders URL")
}
url = parsed
} else {
url = URL(string: "x-apple-reminderkit://")!
}
if values.flag("app"), values.argument(0) == nil, listTarget == nil {
url = URL(string: "x-apple-reminderkit://")!
} else {
let result = try await LinkCommand.resolve(values: values)
guard let parsed = URL(string: result.url) else {
Expand Down
17 changes: 0 additions & 17 deletions Sources/remindctl/ParsedValues+Decode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@ import Commander
import Foundation

enum ParsedValuesError: LocalizedError, CustomStringConvertible {
case missingOption(String)
case invalidOption(String)
case missingArgument(String)

var description: String {
switch self {
case .missingOption(let name):
return "Missing required option: --\(name)"
case .invalidOption(let name):
return "Invalid value for option: --\(name)"
case .missingArgument(let name):
return "Missing required argument: \(name)"
}
Expand All @@ -31,17 +25,6 @@ extension ParsedValues {
options[label]?.last
}

func optionValues(_ label: String) -> [String] {
options[label] ?? []
}

func optionRequired(_ label: String) throws -> String {
guard let value = option(label), !value.isEmpty else {
throw ParsedValuesError.missingOption(label)
}
return value
}

func argument(_ index: Int) -> String? {
guard positional.indices.contains(index) else { return nil }
return positional[index]
Expand Down