mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-07 03:50:08 +02:00
👌 Add PATH to SystemShell
This commit is contained in:
@ -16,6 +16,13 @@ class ShellTest: XCTestCase {
|
||||
.contains("Copyright (c) The PHP Group"))
|
||||
}
|
||||
|
||||
func test_system_shell_has_path() {
|
||||
let systemShell = NxtShell.shared as! SystemShell
|
||||
|
||||
XCTAssertTrue(systemShell.PATH.contains(":/usr/local/bin"))
|
||||
XCTAssertTrue(systemShell.PATH.contains(":/usr/bin"))
|
||||
}
|
||||
|
||||
func test_we_can_predefine_responses_for_dummy_shell() {
|
||||
let expectedPhpOutput = """
|
||||
PHP 8.1.10 (cli) (built: Sep 3 2022 12:09:27) (NTS)
|
||||
|
@ -11,7 +11,24 @@ import Foundation
|
||||
class SystemShell: Shellable {
|
||||
public var launchPath: String = "/bin/sh"
|
||||
|
||||
public var exports: String = ""
|
||||
public var PATH: String = {
|
||||
let task = Process()
|
||||
task.launchPath = "/bin/zsh"
|
||||
|
||||
// We need an interactive shell so the user's PATH is loaded in correctly
|
||||
task.arguments = ["--login", "-ilc", "echo $PATH"]
|
||||
|
||||
let pipe = Pipe()
|
||||
task.standardOutput = pipe
|
||||
task.launch()
|
||||
|
||||
return String(
|
||||
data: pipe.fileHandleForReading.readDataToEndOfFile(),
|
||||
encoding: String.Encoding.utf8
|
||||
) ?? ""
|
||||
}()
|
||||
|
||||
var exports: String = ""
|
||||
|
||||
private func getShellProcess(for command: String) -> Process {
|
||||
var completeCommand = ""
|
||||
@ -19,7 +36,7 @@ class SystemShell: Shellable {
|
||||
// Basic export (PATH)
|
||||
completeCommand += "export PATH=\(Paths.binPath):$PATH && "
|
||||
|
||||
// Put additional exports in between
|
||||
// Put additional exports (as defined by the user) in between
|
||||
if !self.exports.isEmpty {
|
||||
completeCommand += "\(self.exports) && "
|
||||
}
|
||||
@ -32,6 +49,8 @@ class SystemShell: Shellable {
|
||||
return task
|
||||
}
|
||||
|
||||
// MARK: - Shellable Protocol
|
||||
|
||||
func syncPipe(_ command: String) -> String {
|
||||
let task = getShellProcess(for: command)
|
||||
let pipe = Pipe()
|
||||
|
Reference in New Issue
Block a user