Skip to content

Commit 123cbbd

Browse files
committed
Ensure all casks are upgraded, including those with auto-update enabled
1 parent c345eae commit 123cbbd

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

Sources/Zero/Commands/Update.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ private extension ZeroRunner {
6868
let verboseFlags: [String] = verbose ? ["--verbose"] : []
6969
try ZeroRunner.runTask("brew", arguments: ["update"] + verboseFlags)
7070
try ZeroRunner.runTask("brew", arguments: ["upgrade"] + verboseFlags)
71-
try ZeroRunner.runTask("brew", arguments: ["cask", "upgrade"] + verboseFlags)
71+
try ZeroRunner.runShell(
72+
"brew cask outdated --greedy --verbose | " +
73+
"grep -v '(latest)' | " +
74+
"awk '{print $1}' | " +
75+
"xargs brew cask reinstall"
76+
)
7277
}
7378

7479
/// Check and apply app store updates.

Sources/Zero/Runner.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ struct ZeroRunner {
7575
)
7676
}
7777

78+
/// Run a shell statement synchronously, printing the command before
79+
/// running.
80+
///
81+
/// - Warning: Do not use this with unsanitized user input.
82+
static func runShell(
83+
_ command: String,
84+
at directory: Path? = nil
85+
) throws {
86+
self.printCommand(command)
87+
try Task.run("/bin/sh", arguments: ["-c", command], directory: directory?.string)
88+
}
89+
7890
/// Run an executable with the given arguments, printing the command before
7991
/// running.
8092
static func runTask(
@@ -172,7 +184,7 @@ private extension ZeroRunner {
172184
}
173185
}
174186

175-
static func printCommand(_ executable: String, _ arguments: [String]) {
187+
static func printCommand(_ executable: String, _ arguments: [String] = []) {
176188
let escapedCommand: [String] = [executable] + arguments.map(Task.escapeArgument)
177189
Term.stdout <<< TTY.commandMessage(escapedCommand.joined(separator: " "))
178190
}

0 commit comments

Comments
 (0)