-
Notifications
You must be signed in to change notification settings - Fork 3
/
UpdateCommand.swift
42 lines (37 loc) · 1.45 KB
/
UpdateCommand.swift
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
import ArgumentParser
import Foundation
struct UpdateCommand: ParsableCommand {
static var configuration = CommandConfiguration(commandName: "update", abstract: "Updates dependencies")
@Argument(help: "Path of the swift package") var folder: String = "."
@ArgumentParser.Flag(help: "Do not change version requirements in the Package.swift file.") private var keepRequirements: Bool = false
func run() throws {
let folder = URL(fileURLWithPath: folder)
guard folder.hasDirectoryPath else {
print("Folder argument must be a directory.")
throw ExitCode.failure
}
do {
var dependencies = try Dependency.loadDependencies(from: folder)
dependencies = dependencies.filter { $0.update != nil && $0.update != .skipped }
if keepRequirements {
dependencies = dependencies.filter {
if case .withChangingRequirements = $0.update {
return false
} else {
return true
}
}
}
if dependencies.isEmpty {
print("Everything is already up-to-date!".green)
} else {
try dependencies.forEach {
try $0.update(in: folder)
}
}
} catch {
print(error.localizedDescription)
throw ExitCode.failure
}
}
}