Skip to content

Commit ec671f8

Browse files
authored
Merge pull request #25 from dirtyhenry/fake
Add catch-up flag
2 parents 28846c9 + 6c741a6 commit ec671f8

File tree

5 files changed

+23
-18
lines changed

5 files changed

+23
-18
lines changed

.swift-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.5
1+
5.9

Package.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.5
1+
// swift-tools-version:5.9
22

33
import PackageDescription
44

Sources/Pomodoro/Hook.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ extension Hook {
1616
private var scriptURL: URL {
1717
switch self {
1818
case .didStart:
19-
return Environment.dotDirectory.appendingPathComponent(Hook.didStartScript)
19+
Environment.dotDirectory.appendingPathComponent(Hook.didStartScript)
2020
case .didFinish:
21-
return Environment.dotDirectory.appendingPathComponent(Hook.didFinishScript)
21+
Environment.dotDirectory.appendingPathComponent(Hook.didFinishScript)
2222
}
2323
}
2424

@@ -43,7 +43,7 @@ extension Hook {
4343
formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
4444

4545
canBeExecuted { executable, path in
46-
if executable, let path = path {
46+
if executable, let path {
4747
let task = Process.launchedProcess(launchPath: path, arguments: [
4848
formatter.string(from: description.startDate),
4949
formatter.string(from: description.endDate),

Sources/Pomodoro/TimerViewCLI.swift

+13-11
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,22 @@ public class TimerViewCLI {
2828
/// Starts the timer for the specified duration.
2929
///
3030
/// - Parameter pomodoro: the description of the Pomodoro.
31-
public func start(pomodoro: PomodoroDescription) {
32-
let timerViewModel = TimerViewModel(timeInterval: pomodoro.duration)
33-
self.timerViewModel = timerViewModel
31+
public func start(pomodoro: PomodoroDescription, shouldExitRightAway: Bool = false) {
32+
if !shouldExitRightAway {
33+
let timerViewModel = TimerViewModel(timeInterval: pomodoro.duration)
34+
self.timerViewModel = timerViewModel
3435

35-
Hook.didStart.execute(description: pomodoro, completionHandler: hookCompletionHandler)
36+
Hook.didStart.execute(description: pomodoro, completionHandler: hookCompletionHandler)
3637

37-
output.write(string: "🍅 from \(pomodoro.formattedStartDate) to \(pomodoro.formattedEndDate)\n")
38-
sleepTime = pomodoro.duration / TimeInterval(outputLength)
39-
while !timerViewModel.outputs.progress.isFinished {
40-
outputLine(for: timerViewModel.outputs.progress.fractionCompleted)
41-
Thread.sleep(forTimeInterval: sleepTime)
38+
output.write(string: "🍅 from \(pomodoro.formattedStartDate) to \(pomodoro.formattedEndDate)\n")
39+
sleepTime = pomodoro.duration / TimeInterval(outputLength)
40+
while !timerViewModel.outputs.progress.isFinished {
41+
outputLine(for: timerViewModel.outputs.progress.fractionCompleted)
42+
Thread.sleep(forTimeInterval: sleepTime)
43+
}
44+
outputLine(for: 1.0)
45+
output.write(string: "\nPomodoro ended\n")
4246
}
43-
outputLine(for: 1.0)
44-
output.write(string: "\nPomodoro ended\n")
4547

4648
Hook.didFinish.execute(description: pomodoro, completionHandler: hookCompletionHandler)
4749
LogWriter().writeLog(pomodoroDescription: pomodoro)

Sources/PomodoroCLI/RootCommand.swift

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ struct PomodoroCLI: ParsableCommand {
1111
@Option(name: .shortAndLong, help: "The intent of the pomodoro (example: email zero)")
1212
var message: String?
1313

14+
@Flag(name: .shortAndLong, help: "Exit right away (escape-hatch to run hooks only)")
15+
var catchUp: Bool = false
16+
1417
func run() throws {
1518
guard let durationAsTimeInterval = TimeIntervalFormatter().timeInterval(from: duration) else {
1619
CLIUtils.write(message: "Invalid duration: \(duration)")
@@ -19,14 +22,14 @@ struct PomodoroCLI: ParsableCommand {
1922

2023
let pomodoroMessage: String
2124

22-
if let message = message {
25+
if let message {
2326
pomodoroMessage = message
2427
} else {
2528
CLIUtils.write(message: "💁‍♀️ What is the intent of this pomodoro?", foreground: .green)
2629
pomodoroMessage = readLine() ?? ""
2730
}
2831

2932
let pomodoro = PomodoroDescription(duration: durationAsTimeInterval, message: pomodoroMessage)
30-
TimerViewCLI(output: FileHandle.standardOutput).start(pomodoro: pomodoro)
33+
TimerViewCLI(output: FileHandle.standardOutput).start(pomodoro: pomodoro, shouldExitRightAway: catchUp)
3134
}
3235
}

0 commit comments

Comments
 (0)