From 4494a0555f48320f55728042db7309ba8b40af14 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Tue, 20 Sep 2022 00:33:58 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20WIP:=20Shell=20rework?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PHP Monitor.xcodeproj/project.pbxproj | 6 +++++ phpmon/Common/Core/NewShell.swift | 39 +++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 phpmon/Common/Core/NewShell.swift diff --git a/PHP Monitor.xcodeproj/project.pbxproj b/PHP Monitor.xcodeproj/project.pbxproj index d509d82..3e8469f 100644 --- a/PHP Monitor.xcodeproj/project.pbxproj +++ b/PHP Monitor.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 03E36FE728D9219000636F7F /* NewShell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03E36FE628D9219000636F7F /* NewShell.swift */; }; + 03E36FE828D9219000636F7F /* NewShell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03E36FE628D9219000636F7F /* NewShell.swift */; }; 5420395926135DC100FB00FA /* PrefsVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5420395826135DC100FB00FA /* PrefsVC.swift */; }; 5420395F2613607600FB00FA /* Preferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5420395E2613607600FB00FA /* Preferences.swift */; }; 5489625828312FAD004F647A /* CreatedFromFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5489625728312FAD004F647A /* CreatedFromFile.swift */; }; @@ -322,6 +324,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 03E36FE628D9219000636F7F /* NewShell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewShell.swift; sourceTree = ""; }; 5420395826135DC100FB00FA /* PrefsVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrefsVC.swift; sourceTree = ""; }; 5420395E2613607600FB00FA /* Preferences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Preferences.swift; sourceTree = ""; }; 5489625728312FAD004F647A /* CreatedFromFile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreatedFromFile.swift; sourceTree = ""; }; @@ -647,6 +650,7 @@ C4C1019A27C65C6F001FACC2 /* Process.swift */, C40C7F2F27722E8D00DDDCDC /* Logger.swift */, C417DC73277614690015E6EE /* Helpers.swift */, + 03E36FE628D9219000636F7F /* NewShell.swift */, ); path = Core; sourceTree = ""; @@ -1386,6 +1390,7 @@ C41CA5ED2774F8EE00A2C80E /* DomainListVC+Actions.swift in Sources */, C46E206D28299B3800D909D6 /* AppUpdateChecker.swift in Sources */, C412E5FC25700D5300A1FB67 /* HomebrewPackage.swift in Sources */, + 03E36FE728D9219000636F7F /* NewShell.swift in Sources */, C4D9ADBF277610E1007277F4 /* PhpSwitcher.swift in Sources */, C45E76142854A65300B4FE0C /* ServicesManager.swift in Sources */, C4068CAA27B0890D00544CD5 /* MenuBarIcons.swift in Sources */, @@ -1536,6 +1541,7 @@ C4B97B7C275CF20A003F3378 /* App+GlobalHotkey.swift in Sources */, 5489625928313231004F647A /* CreatedFromFile.swift in Sources */, 54D9E0B327E4F51E003B9AD9 /* HotKeysController.swift in Sources */, + 03E36FE828D9219000636F7F /* NewShell.swift in Sources */, C4B97B79275CF1B5003F3378 /* App+ActivationPolicy.swift in Sources */, C4CE3BBB27B324230086CA49 /* MainMenu+Switcher.swift in Sources */, C46E20702829D27F00D909D6 /* AppUpdaterCheckTest.swift in Sources */, diff --git a/phpmon/Common/Core/NewShell.swift b/phpmon/Common/Core/NewShell.swift new file mode 100644 index 0000000..2c7d69c --- /dev/null +++ b/phpmon/Common/Core/NewShell.swift @@ -0,0 +1,39 @@ +// +// NewShell.swift +// PHP Monitor +// +// Created by Nico Verbruggen on 20/09/2022. +// Copyright © 2022 Nico Verbruggen. All rights reserved. +// + +import Foundation + +class NewShell { + static var shared: Shellable! + + public func useTestable(_ expectations: [String: String]) { + Self.shared = TestableShell(expectations: expectations) + } +} + +protocol Shellable { + func pipe(_ command: String) -> String +} + +class SystemShell: Shellable { + func pipe(_ command: String) -> String { + return "shell output" + } +} + +class TestableShell: Shellable { + init(expectations: [String: String]) { + self.expectations = expectations + } + + var expectations: [String: String] = [:] + + func pipe(_ command: String) -> String { + return expectations[command] ?? "" + } +}