From 3139bfc8118c479e4ff91577c63520f6e869ed9f Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Wed, 19 Feb 2025 01:07:25 +0100 Subject: [PATCH 1/4] Renamed the OutdatedDependenciesTask task in the library target as UpdateDependenciesTask and also, added support for the "checkOutdated" flag to its "callAsFunction(at: checkOutdated: )" function. --- ...ask.swift => UpdateDependenciesTask.swift} | 10 +++++--- ...wift => UpdateDependenciesTaskTests.swift} | 25 +++++++++++-------- 2 files changed, 21 insertions(+), 14 deletions(-) rename Library/Sources/Public/Tasks/{OutdatedDependenciesTask.swift => UpdateDependenciesTask.swift} (71%) rename Test/Sources/Cases/Public/Tasks/{OutdatedDependenciesTaskTests.swift => UpdateDependenciesTaskTests.swift} (57%) diff --git a/Library/Sources/Public/Tasks/OutdatedDependenciesTask.swift b/Library/Sources/Public/Tasks/UpdateDependenciesTask.swift similarity index 71% rename from Library/Sources/Public/Tasks/OutdatedDependenciesTask.swift rename to Library/Sources/Public/Tasks/UpdateDependenciesTask.swift index 38a33de..e404b6b 100644 --- a/Library/Sources/Public/Tasks/OutdatedDependenciesTask.swift +++ b/Library/Sources/Public/Tasks/UpdateDependenciesTask.swift @@ -1,6 +1,6 @@ import Foundation -public struct OutdatedDependenciesTask { +public struct UpdateDependenciesTask { // MARK: Properties @@ -14,7 +14,7 @@ public struct OutdatedDependenciesTask { // MARK: Functions - public func callAsFunction(at location: URL? = nil) async throws (TerminalServiceError) { + public func callAsFunction(at location: URL? = nil, checkOutdated: Bool = false) async throws (TerminalServiceError) { let executableURL = URL(at: "/usr/bin/swift") var arguments: [String] = ["package", "update"] @@ -23,8 +23,10 @@ public struct OutdatedDependenciesTask { arguments.append(contentsOf: ["--package-path", location.pathString]) } - arguments.append("--dry-run") - + if checkOutdated { + arguments.append("--dry-run") + } + try await terminalService.run(executableURL, arguments: arguments) } diff --git a/Test/Sources/Cases/Public/Tasks/OutdatedDependenciesTaskTests.swift b/Test/Sources/Cases/Public/Tasks/UpdateDependenciesTaskTests.swift similarity index 57% rename from Test/Sources/Cases/Public/Tasks/OutdatedDependenciesTaskTests.swift rename to Test/Sources/Cases/Public/Tasks/UpdateDependenciesTaskTests.swift index b79a211..6208277 100644 --- a/Test/Sources/Cases/Public/Tasks/OutdatedDependenciesTaskTests.swift +++ b/Test/Sources/Cases/Public/Tasks/UpdateDependenciesTaskTests.swift @@ -3,23 +3,28 @@ import Testing @testable import ColibriLibrary -struct OutdatedDependenciesTaskTests { +struct UpdateDependenciesTaskTests { - @Test(arguments: [nil, URL.someCurrentFolder]) - func task(at location: URL?) async throws { + @Test(arguments: [nil, URL.someCurrentFolder], [false, true]) + func task(at location: URL?, checkOutdated: Bool) async throws { // GIVEN let terminalService = TerminalServiceSpy() - let task = OutdatedDependenciesTask(terminalService: terminalService) + let task = UpdateDependenciesTask(terminalService: terminalService) // WHEN - try await task(at: location) + try await task(at: location, checkOutdated: checkOutdated) // THEN let executableURL = URL(at: "/usr/bin/swift") - let arguments = if let location { - ["package", "update", "--package-path", location.pathString, "--dry-run"] + + var arguments = if let location { + ["package", "update", "--package-path", location.pathString] } else { - ["package", "update", "--dry-run"] + ["package", "update"] + } + + if checkOutdated { + arguments.append("--dry-run") } #expect(terminalService.actions.count == 1) @@ -30,12 +35,12 @@ struct OutdatedDependenciesTaskTests { func task(at location: URL?, throws error: TerminalServiceError) async throws { // GIVEN let terminalService = TerminalServiceMock(action: .error(error)) - let task = BuildProjectTask(terminalService: terminalService) + let task = UpdateDependenciesTask(terminalService: terminalService) // WHEN // THEN await #expect(throws: error) { - try await task(at: location) + try await task(at: location, checkOutdated: .random()) } } -- 2.47.1 From 26a5e4232a88729c8d304f6004508f1241306798 Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Wed, 19 Feb 2025 01:08:24 +0100 Subject: [PATCH 2/4] Updated the OutdatedCommand command in the executable target to use the UpdateDependenciesTask task with the "checkOutdated" flag enabled. --- Executable/Sources/Commands/OutdatedCommand.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Executable/Sources/Commands/OutdatedCommand.swift b/Executable/Sources/Commands/OutdatedCommand.swift index 686da2b..2027bb6 100644 --- a/Executable/Sources/Commands/OutdatedCommand.swift +++ b/Executable/Sources/Commands/OutdatedCommand.swift @@ -20,9 +20,9 @@ extension Colibri { mutating func run() async throws { let terminalService = TerminalService() - let outdatedDependencies = OutdatedDependenciesTask(terminalService: terminalService) + let updateDependencies = UpdateDependenciesTask(terminalService: terminalService) - try await outdatedDependencies(at: options.locationURL) + try await updateDependencies(at: options.locationURL, checkOutdated: true) } } -- 2.47.1 From 97467f2ed879f686584d11308fb679278e1d4fd4 Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Wed, 19 Feb 2025 01:09:12 +0100 Subject: [PATCH 3/4] Implemented the UpdateCommand command in the executable target. --- .../Sources/Commands/UpdateCommand.swift | 29 +++++++++++++++++++ .../Sources/Options/UpdateOptions.swift | 13 +++++++++ 2 files changed, 42 insertions(+) create mode 100644 Executable/Sources/Commands/UpdateCommand.swift create mode 100644 Executable/Sources/Options/UpdateOptions.swift diff --git a/Executable/Sources/Commands/UpdateCommand.swift b/Executable/Sources/Commands/UpdateCommand.swift new file mode 100644 index 0000000..eaf869a --- /dev/null +++ b/Executable/Sources/Commands/UpdateCommand.swift @@ -0,0 +1,29 @@ +import ArgumentParser +import ColibriLibrary + +extension Colibri { + struct Update: AsyncParsableCommand { + + // MARK: Properties + + static let configuration = CommandConfiguration( + commandName: "update-dependencies", + abstract: "Update package dependencies in a Hummingbird app", + helpNames: .shortAndLong, + aliases: ["update"] + ) + + @OptionGroup var options: Options + + // MARK: Functions + + mutating func run() async throws { + let terminalService = TerminalService() + + let updateDependencies = UpdateDependenciesTask(terminalService: terminalService) + + try await updateDependencies(at: options.locationURL) + } + + } +} diff --git a/Executable/Sources/Options/UpdateOptions.swift b/Executable/Sources/Options/UpdateOptions.swift new file mode 100644 index 0000000..8dcb812 --- /dev/null +++ b/Executable/Sources/Options/UpdateOptions.swift @@ -0,0 +1,13 @@ +import ArgumentParser +import ColibriLibrary + +extension Colibri.Update { + struct Options: ParsableArguments, Locationable { + + // MARK: Properties + + @Option(name: .shortAndLong) + var location: String? + + } +} -- 2.47.1 From 53086b0369daf6a4fa953014083c0b0033b2fe9a Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Wed, 19 Feb 2025 01:10:28 +0100 Subject: [PATCH 4/4] Added the Update command to the subcommands lists of the Colibri command in the executable target. --- Executable/Sources/Colibri.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Executable/Sources/Colibri.swift b/Executable/Sources/Colibri.swift index 288e88b..0aee64c 100644 --- a/Executable/Sources/Colibri.swift +++ b/Executable/Sources/Colibri.swift @@ -10,7 +10,8 @@ struct Colibri: AsyncParsableCommand { subcommands: [ Build.self, Create.self, - Outdated.self + Outdated.self, + Update.self ], defaultSubcommand: Create.self ) -- 2.47.1