mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2026-03-26 14:10:07 +01:00
✅ Use protocol so custom exports are easier to test
This commit is contained in:
@@ -98,8 +98,7 @@ class Actions {
|
||||
|
||||
public func openGlobalComposerFolder() {
|
||||
// Check if we have a custom COMPOSER_HOME set
|
||||
if let shell = App.shared.container.shell as? TrackedShell,
|
||||
let folder = shell.customExports["COMPOSER_HOME"] {
|
||||
if let folder = App.shared.container.shell.exports["COMPOSER_HOME"] {
|
||||
let file = URL(string: "file://\(folder)/composer.json".replacingTildeWithHomeDirectory)!
|
||||
return NSWorkspace.shared.activateFileViewerSelecting([file] as [URL])
|
||||
}
|
||||
|
||||
@@ -60,27 +60,10 @@ final class TrackedShell: ShellProtocol {
|
||||
}
|
||||
|
||||
// MARK: - Custom exports
|
||||
// (probably should be part of the protocol?)
|
||||
|
||||
var customExports: [String: String] {
|
||||
if let shell = self.shell as? RealShell {
|
||||
return shell.exports
|
||||
} else if let shell = self.shell as? TestableShell {
|
||||
return shell.exports
|
||||
} else {
|
||||
assertionFailure("This shell does not support retrieving custom exports.")
|
||||
return [:]
|
||||
}
|
||||
}
|
||||
|
||||
func setCustomExports(_ variables: [String: String]) {
|
||||
if let shell = self.shell as? RealShell {
|
||||
shell.exports = variables
|
||||
} else if let shell = self.shell as? TestableShell {
|
||||
shell.exports = variables
|
||||
} else {
|
||||
assertionFailure("Custom exports were set in `config.json`, but not applied because the shell does not support it.")
|
||||
}
|
||||
var exports: [String: String] {
|
||||
get { shell.exports }
|
||||
set { shell.exports = newValue }
|
||||
}
|
||||
|
||||
func reloadEnvPath() {
|
||||
|
||||
@@ -8,12 +8,18 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
protocol ShellProtocol {
|
||||
protocol ShellProtocol: AnyObject {
|
||||
/**
|
||||
The PATH for the current shell.
|
||||
*/
|
||||
var PATH: String { get }
|
||||
|
||||
/**
|
||||
Exports are additional environment variables set by the user via the custom configuration.
|
||||
These are populated when the configuration file is being loaded.
|
||||
*/
|
||||
var exports: [String: String] { get set }
|
||||
|
||||
/**
|
||||
Run a command synchronously. Use with caution!
|
||||
|
||||
|
||||
@@ -91,9 +91,8 @@ extension Preferences {
|
||||
Log.info("Configuring the additional exports...")
|
||||
Log.info("Custom exports: \(exports.description)")
|
||||
|
||||
if let shell = App.shared.container.shell as? TrackedShell {
|
||||
shell.setCustomExports(exports)
|
||||
}
|
||||
// Assign the new exports values
|
||||
container.shell.exports = exports
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user