mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-07 03:50:08 +02:00
👌 Add additional commentary to new shell classes
This commit is contained in:
@ -656,8 +656,6 @@
|
||||
C4EC1E72279DFCF40010F296 /* Events.swift */,
|
||||
C4B5853D2770FE3900DA4FBE /* Command.swift */,
|
||||
C4B5853B2770FE3900DA4FBE /* Paths.swift */,
|
||||
C4B5853C2770FE3900DA4FBE /* Shell.swift */,
|
||||
C42E3BF328A9BF5100AFECFC /* Shell+PATH.swift */,
|
||||
C4C1019A27C65C6F001FACC2 /* Process.swift */,
|
||||
C40C7F2F27722E8D00DDDCDC /* Logger.swift */,
|
||||
C417DC73277614690015E6EE /* Helpers.swift */,
|
||||
@ -883,6 +881,15 @@
|
||||
path = Next;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
C46EBC4C28DB9F43007ACC74 /* Pending Removal */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
C4B5853C2770FE3900DA4FBE /* Shell.swift */,
|
||||
C42E3BF328A9BF5100AFECFC /* Shell+PATH.swift */,
|
||||
);
|
||||
path = "Pending Removal";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
C47331A0247093AC009A0597 /* Menu */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@ -977,6 +984,7 @@
|
||||
C4B5853A2770FE2500DA4FBE /* Common */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
C46EBC4C28DB9F43007ACC74 /* Pending Removal */,
|
||||
C40C7F2127721F7300DDDCDC /* Core */,
|
||||
54B20EDF263AA22C00D3250E /* PHP */,
|
||||
C44CCD4327AFE93300CE40E5 /* Errors */,
|
||||
|
@ -7,6 +7,8 @@
|
||||
|
||||
import Cocoa
|
||||
|
||||
// TODO: Enable this to see where deprecations and replacements are needed.
|
||||
// @available(*, deprecated, message: "Use the new replacement `NxtShell` instead")
|
||||
public class Shell {
|
||||
|
||||
// MARK: - Invoke static functions
|
@ -26,6 +26,7 @@ struct CustomPrefs: Decodable {
|
||||
return self.environmentVariables != nil && !self.environmentVariables!.keys.isEmpty
|
||||
}
|
||||
|
||||
@available(*, deprecated, message: "Use `setCustomEnvironmentVariables` instead")
|
||||
public func getEnvironmentVariables() -> String {
|
||||
return self.environmentVariables!.map { (key, value) in
|
||||
return "export \(key)=\(value)"
|
||||
|
@ -9,9 +9,26 @@
|
||||
import Foundation
|
||||
|
||||
class SystemShell: Shellable {
|
||||
public var launchPath: String = "/bin/sh"
|
||||
/**
|
||||
The launch path of the terminal in question that is used.
|
||||
On macOS, we use /bin/sh since it's pretty fast.
|
||||
*/
|
||||
private(set) var launchPath: String = "/bin/sh"
|
||||
|
||||
public var PATH: String = {
|
||||
/**
|
||||
For some commands, we need to know what's in the user's PATH.
|
||||
The entire PATH is retrieved here, so we can set the PATH in our own terminal as necessary.
|
||||
*/
|
||||
private(set) var PATH: String = { return SystemShell.getPath() }()
|
||||
|
||||
/**
|
||||
Exports are additional environment variables set by the user via the custom configuration.
|
||||
These are populated when the configuration file is being loaded.
|
||||
*/
|
||||
private(set) var exports: String = ""
|
||||
|
||||
/** Retrieves the user's PATH by opening an interactive shell and echoing $PATH. */
|
||||
private static func getPath() -> String {
|
||||
let task = Process()
|
||||
task.launchPath = "/bin/zsh"
|
||||
|
||||
@ -26,10 +43,12 @@ class SystemShell: Shellable {
|
||||
data: pipe.fileHandleForReading.readDataToEndOfFile(),
|
||||
encoding: String.Encoding.utf8
|
||||
) ?? ""
|
||||
}()
|
||||
|
||||
var exports: String = ""
|
||||
}
|
||||
|
||||
/**
|
||||
Create a process that will run the required shell with the appropriate arguments.
|
||||
This process still needs to be started, or one can attach output handlers.
|
||||
*/
|
||||
private func getShellProcess(for command: String) -> Process {
|
||||
var completeCommand = ""
|
||||
|
||||
@ -49,6 +68,18 @@ class SystemShell: Shellable {
|
||||
return task
|
||||
}
|
||||
|
||||
// MARK: - Public API
|
||||
|
||||
/**
|
||||
Set custom environment variables.
|
||||
These will be exported when a command is executed.
|
||||
*/
|
||||
public func setCustomEnvironmentVariables(_ variables: [String: String]) {
|
||||
self.exports = variables.map { (key, value) in
|
||||
return "export \(key)=\(value)"
|
||||
}.joined(separator: "&&")
|
||||
}
|
||||
|
||||
// MARK: - Shellable Protocol
|
||||
|
||||
func syncPipe(_ command: String) -> String {
|
||||
|
Reference in New Issue
Block a user