Skip to content

Commit

Permalink
Output warning instead of fail if a dependency could not be found (#104)
Browse files Browse the repository at this point in the history
In case a dependency is not required on all platforms, it might not
be defined - in this case show a warning instead of fail.
  • Loading branch information
Nef10 authored May 5, 2022
1 parent bca7b75 commit df6e696
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct UpdateCommand: ParsableCommand {
func run() throws {
let folder = URL(fileURLWithPath: folder)
guard folder.hasDirectoryPath else {
print("Folder argument must be a directory.")
print("Folder argument must be a directory.".red)
throw ExitCode.failure
}
do {
Expand All @@ -34,7 +34,7 @@ struct UpdateCommand: ParsableCommand {
}
}
} catch {
print(error.localizedDescription)
print(error.localizedDescription.red)
throw ExitCode.failure
}
}
Expand Down
24 changes: 16 additions & 8 deletions Sources/SwiftDependencyUpdaterLibrary/Update.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,23 @@ enum Update: Equatable {
case let .withChangingRequirements(version):
print("Updating \(dependency.name): \(dependency.resolvedVersion.versionNumberOrRevision) -> \(version)".bold)
let swiftPackage = SwiftPackage(in: folder)
let packageUpdate = try swiftPackage.performUpdate(self, of: dependency)
print("Updated Package.swift".green)
if packageUpdate {
try shellOut(to: "swift", arguments: ["package", "--package-path", "\"\(folder.path)\"", "update", dependency.name ])
print("Resolved to new version".green)
} else {
try shellOut(to: "swift", arguments: ["package", "--package-path", "\"\(folder.path)\"", "update", "resolve", ])
print("Resolved Version".green)
do {
let packageUpdate = try swiftPackage.performUpdate(self, of: dependency)
print("Updated Package.swift".green)
if packageUpdate {
try shellOut(to: "swift", arguments: ["package", "--package-path", "\"\(folder.path)\"", "update", dependency.name ])
print("Resolved to new version".green)
} else {
try shellOut(to: "swift", arguments: ["package", "--package-path", "\"\(folder.path)\"", "update", "resolve", ])
print("Resolved Version".green)
}
} catch let SwiftPackageError.resultCountMismatch(name, count) where count == 0 { // false positive, count is an integer swiftlint:disable:this empty_count
print("Warning: Could not find version requirement for \(name) in Package.swift - " +
"this could be due to the dependency only beeing required on a specific platform.".yellow)
} catch {
throw error
}

case let .withoutChangingRequirements(version):
print("Updating \(dependency.name): \(dependency.resolvedVersion.versionNumberOrRevision) -> \(version)".bold)
try shellOut(to: "swift", arguments: ["package", "--package-path", "\"\(folder.path)\"", "update", dependency.name, ])
Expand Down

0 comments on commit df6e696

Please sign in to comment.