-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathCLI.swift
More file actions
102 lines (81 loc) · 2.59 KB
/
CLI.swift
File metadata and controls
102 lines (81 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import ArgumentParser
import Foundation
private let reminders = Reminders()
private struct ShowLists: ParsableCommand {
static let configuration = CommandConfiguration(
abstract: "Print the name of lists to pass to other commands")
func run() {
reminders.showLists()
}
}
private struct Show: ParsableCommand {
static let configuration = CommandConfiguration(
abstract: "Print the items on the given list")
@Argument(
help: "The list to print items from, see 'show-lists' for names")
var listName: String
func run() {
reminders.showListItems(withName: self.listName)
}
}
private struct Add: ParsableCommand {
static let configuration = CommandConfiguration(
abstract: "Add a reminder to a list")
@Argument(
help: "The list to add to, see 'show-lists' for names")
var listName: String
@Argument(
parsing: .remaining,
help: "The reminder contents")
var reminder: [String]
@Option(
name: .shortAndLong,
help: "The date the reminder is due")
var dueDate: DateComponents?
func run() {
reminders.addReminder(
string: self.reminder.joined(separator: " "),
toListNamed: self.listName,
dueDate: self.dueDate)
}
}
private struct Complete: ParsableCommand {
static let configuration = CommandConfiguration(
abstract: "Complete a reminder")
@Argument(
help: "The list to complete a reminder on, see 'show-lists' for names")
var listName: String
@Argument(
help: "The index of the reminder to complete, see 'show' for indexes")
var index: Int
func run() {
reminders.complete(itemAtIndex: self.index, onListNamed: self.listName)
}
}
private struct Punt: ParsableCommand {
static let configuration = CommandConfiguration(
abstract: "Punt a due date to next week")
@Argument(
help: "The list to complete a reminder on, see 'show-lists' for names")
var listName: String
@Argument(
help: "The index of the reminder to complete, see 'show' for indexes")
var indexes: [Int]
func run() {
reminders.punt(self.indexes, onListNamed: self.listName)
}
}
public struct CLI: ParsableCommand {
public static let configuration = CommandConfiguration(
commandName: "reminders",
abstract: "Interact with macOS Reminders from the command line",
subcommands: [
Add.self,
Complete.self,
Punt.self,
Show.self,
ShowLists.self,
]
)
public init() {}
}