Implemented the Create subcommand (#5)
This PR contains the work done to add the *Build* subcommand that build a *Hummingbird* project from the command line to the `Colibri` command. Reviewed-on: #5 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 #5.
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import Foundation
|
||||
|
||||
public protocol Locationable {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
var location: String? { get set }
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Locationable+Properties
|
||||
|
||||
public extension Locationable {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
var locationURL: URL? {
|
||||
location.flatMap { URL(fileURLWithPath: $0) }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import Foundation
|
||||
|
||||
public struct BuildProjectTask {
|
||||
|
||||
// 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] = ["build"]
|
||||
|
||||
if let location {
|
||||
arguments.append(contentsOf: ["--package-path", location.pathString])
|
||||
}
|
||||
|
||||
try await terminalService.run(executableURL, arguments: arguments)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user