Implemented the Open subcommand. (#9)
This PR contains the work done to implement the `Open` subcommand to the `colibri` executable, which open a *Hummingbird* project with either Visual Studio Code or Xcode. Reviewed-on: #9 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 #9.
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
public enum IDE: String {
|
||||
case vscode
|
||||
case xcode
|
||||
}
|
||||
|
||||
// MARK: - Extension
|
||||
|
||||
extension IDE {
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
static func random() -> IDE {
|
||||
.allCases.randomElement() ?? .xcode
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - CaseIterable
|
||||
|
||||
extension IDE: CaseIterable {}
|
||||
@@ -0,0 +1,44 @@
|
||||
import Foundation
|
||||
|
||||
public struct OpenProjectTask {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
private let terminalService: TerminalServicing
|
||||
|
||||
// MARK: Initialisers
|
||||
|
||||
public init(terminalService: TerminalServicing) {
|
||||
self.terminalService = terminalService
|
||||
}
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
public func callAsFunction(with ide: IDE, at location: URL? = nil) async throws (TerminalServiceError) {
|
||||
let executableURL: URL = switch ide {
|
||||
case .vscode: .init(at: "/usr/local/bin/code")
|
||||
case .xcode: .init(at: "/usr/bin/open")
|
||||
}
|
||||
|
||||
let locationPath = switch ide {
|
||||
case .vscode: location?.pathString ?? "."
|
||||
case .xcode: location?.appendingPath(.Path.package).pathString ?? .Path.package
|
||||
}
|
||||
|
||||
let arguments: [String] = switch ide {
|
||||
case .vscode: [locationPath]
|
||||
case .xcode: ["-a", "Xcode", locationPath]
|
||||
}
|
||||
|
||||
try await terminalService.run(executableURL, arguments: arguments)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - String+Constants
|
||||
|
||||
private extension String {
|
||||
enum Path {
|
||||
static let package = "Package.swift"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user