Implemented the Clean subcommand (#8)
This PR contains the work done to implement the `Update` subcommand that clean the *Hummingbird* project. Reviewed-on: #8 Co-authored-by: Javier Cicchelli <javier@rock-n-code.com> Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
This commit was merged in pull request #8.
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import Foundation
|
||||
|
||||
public struct CleanProjectTask {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
private let terminalService: TerminalServicing
|
||||
|
||||
// MARK: Initialisers
|
||||
|
||||
public init(terminalService: TerminalServicing) {
|
||||
self.terminalService = terminalService
|
||||
}
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
public func callAsFunction(
|
||||
at location: URL? = nil,
|
||||
shouldReset: Bool = false,
|
||||
purgeCache: Bool = false
|
||||
) async throws (TerminalServiceError) {
|
||||
let executableURL = URL(at: "/usr/bin/swift")
|
||||
|
||||
var arguments: [String] = ["package"]
|
||||
|
||||
if let location {
|
||||
arguments.append(contentsOf: ["--package-path", location.pathString])
|
||||
}
|
||||
|
||||
arguments.insert("clean", at: 1)
|
||||
|
||||
try await terminalService.run(executableURL, arguments: arguments)
|
||||
|
||||
if shouldReset {
|
||||
arguments.remove(at: 1)
|
||||
arguments.insert("reset", at: 1)
|
||||
|
||||
try await terminalService.run(executableURL, arguments: arguments)
|
||||
}
|
||||
|
||||
if purgeCache {
|
||||
arguments.remove(at: 1)
|
||||
arguments.insert("purge-cache", at: 1)
|
||||
|
||||
try await terminalService.run(executableURL, arguments: arguments)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user