Implemented the Outdated subcommand (#6)
This PR contains the work done to implement the `Outdated` subcommand that check for outdated package dependencies in a *Hummingbird* project. Reviewed-on: #6 Co-authored-by: Javier Cicchelli <javier@rock-n-code.com> Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
This commit is contained in:
parent
6a3b9b5141
commit
7ee071010d
@ -9,7 +9,8 @@ struct Colibri: AsyncParsableCommand {
|
|||||||
abstract: "The utility to manage your Hummingbird apps",
|
abstract: "The utility to manage your Hummingbird apps",
|
||||||
subcommands: [
|
subcommands: [
|
||||||
Build.self,
|
Build.self,
|
||||||
Create.self
|
Create.self,
|
||||||
|
Outdated.self
|
||||||
],
|
],
|
||||||
defaultSubcommand: Create.self
|
defaultSubcommand: Create.self
|
||||||
)
|
)
|
||||||
|
29
Executable/Sources/Commands/OutdatedCommand.swift
Normal file
29
Executable/Sources/Commands/OutdatedCommand.swift
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import ArgumentParser
|
||||||
|
import ColibriLibrary
|
||||||
|
|
||||||
|
extension Colibri {
|
||||||
|
struct Outdated: AsyncParsableCommand {
|
||||||
|
|
||||||
|
// MARK: Properties
|
||||||
|
|
||||||
|
static let configuration = CommandConfiguration(
|
||||||
|
commandName: "outdated-dependencies",
|
||||||
|
abstract: "Check for outdated package dependencies in a Hummingbird app",
|
||||||
|
helpNames: .shortAndLong,
|
||||||
|
aliases: ["outdated"]
|
||||||
|
)
|
||||||
|
|
||||||
|
@OptionGroup var options: Options
|
||||||
|
|
||||||
|
// MARK: Functions
|
||||||
|
|
||||||
|
mutating func run() async throws {
|
||||||
|
let terminalService = TerminalService()
|
||||||
|
|
||||||
|
let outdatedDependencies = OutdatedDependenciesTask(terminalService: terminalService)
|
||||||
|
|
||||||
|
try await outdatedDependencies(at: options.locationURL)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
13
Executable/Sources/Options/OutdatedOptions.swift
Normal file
13
Executable/Sources/Options/OutdatedOptions.swift
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import ArgumentParser
|
||||||
|
import ColibriLibrary
|
||||||
|
|
||||||
|
extension Colibri.Outdated {
|
||||||
|
struct Options: ParsableArguments, Locationable {
|
||||||
|
|
||||||
|
// MARK: Properties
|
||||||
|
|
||||||
|
@Option(name: .shortAndLong)
|
||||||
|
var location: String?
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -16,7 +16,7 @@ extension URL {
|
|||||||
|
|
||||||
var pathString: String {
|
var pathString: String {
|
||||||
if #available(macOS 13.0, *) {
|
if #available(macOS 13.0, *) {
|
||||||
path(percentEncoded: true)
|
path(percentEncoded: false)
|
||||||
} else {
|
} else {
|
||||||
path
|
path
|
||||||
}
|
}
|
||||||
|
31
Library/Sources/Public/Tasks/OutdatedDependenciesTask.swift
Normal file
31
Library/Sources/Public/Tasks/OutdatedDependenciesTask.swift
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import Foundation
|
||||||
|
|
||||||
|
public struct OutdatedDependenciesTask {
|
||||||
|
|
||||||
|
// MARK: Properties
|
||||||
|
|
||||||
|
private let terminalService: TerminalServicing
|
||||||
|
|
||||||
|
// MARK: Initialisers
|
||||||
|
|
||||||
|
public init(terminalService: TerminalServicing) {
|
||||||
|
self.terminalService = terminalService
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: Functions
|
||||||
|
|
||||||
|
public func callAsFunction(at location: URL? = nil) async throws (TerminalServiceError) {
|
||||||
|
let executableURL = URL(at: "/usr/bin/swift")
|
||||||
|
|
||||||
|
var arguments: [String] = ["package", "update"]
|
||||||
|
|
||||||
|
if let location {
|
||||||
|
arguments.append(contentsOf: ["--package-path", location.pathString])
|
||||||
|
}
|
||||||
|
|
||||||
|
arguments.append("--dry-run")
|
||||||
|
|
||||||
|
try await terminalService.run(executableURL, arguments: arguments)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -24,8 +24,8 @@ struct URL_ExtensionsTests {
|
|||||||
|
|
||||||
// MARK: Computed tests
|
// MARK: Computed tests
|
||||||
|
|
||||||
@Test(arguments: zip([URL.someFile, .dotFile, .tildeFile, .someURL],
|
@Test(arguments: zip([URL.someFile, .dotFile, .tildeFile, .someEncodedFile, .someURL],
|
||||||
[String.someFilePath, .dotPath, .tildePath, .empty]))
|
[String.someFilePath, .dotPath, .tildePath, .someEncodedPath, .empty]))
|
||||||
func pathString(
|
func pathString(
|
||||||
with url: URL,
|
with url: URL,
|
||||||
expects path: String
|
expects path: String
|
||||||
@ -63,6 +63,7 @@ private extension String {
|
|||||||
static let dotPath = "."
|
static let dotPath = "."
|
||||||
static let empty = ""
|
static let empty = ""
|
||||||
static let tildePath = "~"
|
static let tildePath = "~"
|
||||||
|
static let someEncodedPath = "/sömê/páth/fîlê"
|
||||||
static let someFilePath = "/some/file/path"
|
static let someFilePath = "/some/file/path"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,6 +71,7 @@ private extension String {
|
|||||||
|
|
||||||
private extension URL {
|
private extension URL {
|
||||||
static let dotFile = URL(at: .dotPath)
|
static let dotFile = URL(at: .dotPath)
|
||||||
|
static let someEncodedFile = URL(at: "/sömê/páth/fîlê")
|
||||||
static let someFile = URL(at: .someFilePath)
|
static let someFile = URL(at: .someFilePath)
|
||||||
static let someURL = URL(string: "https://some.url.path")!
|
static let someURL = URL(string: "https://some.url.path")!
|
||||||
static let tildeFile = URL(at: .tildePath)
|
static let tildeFile = URL(at: .tildePath)
|
||||||
|
@ -0,0 +1,42 @@
|
|||||||
|
import Foundation
|
||||||
|
import Testing
|
||||||
|
|
||||||
|
@testable import ColibriLibrary
|
||||||
|
|
||||||
|
struct OutdatedDependenciesTaskTests {
|
||||||
|
|
||||||
|
@Test(arguments: [nil, URL.someCurrentFolder])
|
||||||
|
func task(at location: URL?) async throws {
|
||||||
|
// GIVEN
|
||||||
|
let terminalService = TerminalServiceSpy()
|
||||||
|
let task = OutdatedDependenciesTask(terminalService: terminalService)
|
||||||
|
|
||||||
|
// WHEN
|
||||||
|
try await task(at: location)
|
||||||
|
|
||||||
|
// THEN
|
||||||
|
let executableURL = URL(at: "/usr/bin/swift")
|
||||||
|
let arguments = if let location {
|
||||||
|
["package", "update", "--package-path", location.pathString, "--dry-run"]
|
||||||
|
} else {
|
||||||
|
["package", "update", "--dry-run"]
|
||||||
|
}
|
||||||
|
|
||||||
|
#expect(terminalService.actions.count == 1)
|
||||||
|
#expect(terminalService.actions[0] == .ran(executableURL, arguments))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(arguments: [nil, URL.someCurrentFolder], [TerminalServiceError.unexpected, .output(""), .captured("")])
|
||||||
|
func task(at location: URL?, throws error: TerminalServiceError) async throws {
|
||||||
|
// GIVEN
|
||||||
|
let terminalService = TerminalServiceMock(action: .error(error))
|
||||||
|
let task = BuildProjectTask(terminalService: terminalService)
|
||||||
|
|
||||||
|
// WHEN
|
||||||
|
// THEN
|
||||||
|
await #expect(throws: error) {
|
||||||
|
try await task(at: location)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user