1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2026-04-01 17:20:09 +02:00

Use protocol so custom exports are easier to test

This commit is contained in:
2026-03-03 17:28:00 +01:00
parent 5ad299ac8e
commit cf27f0e071
4 changed files with 13 additions and 26 deletions

View File

@@ -98,8 +98,7 @@ class Actions {
public func openGlobalComposerFolder() { public func openGlobalComposerFolder() {
// Check if we have a custom COMPOSER_HOME set // Check if we have a custom COMPOSER_HOME set
if let shell = App.shared.container.shell as? TrackedShell, if let folder = App.shared.container.shell.exports["COMPOSER_HOME"] {
let folder = shell.customExports["COMPOSER_HOME"] {
let file = URL(string: "file://\(folder)/composer.json".replacingTildeWithHomeDirectory)! let file = URL(string: "file://\(folder)/composer.json".replacingTildeWithHomeDirectory)!
return NSWorkspace.shared.activateFileViewerSelecting([file] as [URL]) return NSWorkspace.shared.activateFileViewerSelecting([file] as [URL])
} }

View File

@@ -60,27 +60,10 @@ final class TrackedShell: ShellProtocol {
} }
// MARK: - Custom exports // MARK: - Custom exports
// (probably should be part of the protocol?)
var customExports: [String: String] { var exports: [String: String] {
if let shell = self.shell as? RealShell { get { shell.exports }
return shell.exports set { shell.exports = newValue }
} 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.")
}
} }
func reloadEnvPath() { func reloadEnvPath() {

View File

@@ -8,12 +8,18 @@
import Foundation import Foundation
protocol ShellProtocol { protocol ShellProtocol: AnyObject {
/** /**
The PATH for the current shell. The PATH for the current shell.
*/ */
var PATH: String { get } 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! Run a command synchronously. Use with caution!

View File

@@ -91,9 +91,8 @@ extension Preferences {
Log.info("Configuring the additional exports...") Log.info("Configuring the additional exports...")
Log.info("Custom exports: \(exports.description)") Log.info("Custom exports: \(exports.description)")
if let shell = App.shared.container.shell as? TrackedShell { // Assign the new exports values
shell.setCustomExports(exports) container.shell.exports = exports
}
} }
} }
} }