From 8fcaa34cbbb58e61b8831bf6f377f8ce3045a561 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Mon, 30 Jan 2023 13:07:37 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Extra=20CLI=20mode=20(--cli)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xcschemes/PHP Monitor DEV.xcscheme | 4 +++ phpmon/Common/Core/Logger.swift | 3 +- phpmon/Common/Shell/RealShell.swift | 30 +++++++++++++++++++ phpmon/Domain/App/AppDelegate.swift | 5 ++++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/PHP Monitor.xcodeproj/xcshareddata/xcschemes/PHP Monitor DEV.xcscheme b/PHP Monitor.xcodeproj/xcshareddata/xcschemes/PHP Monitor DEV.xcscheme index 33c1688..fad7a23 100644 --- a/PHP Monitor.xcodeproj/xcshareddata/xcschemes/PHP Monitor DEV.xcscheme +++ b/PHP Monitor.xcodeproj/xcshareddata/xcschemes/PHP Monitor DEV.xcscheme @@ -89,6 +89,10 @@ argument = "--v" isEnabled = "NO"> + + diff --git a/phpmon/Common/Core/Logger.swift b/phpmon/Common/Core/Logger.swift index fd939c8..1b43581 100644 --- a/phpmon/Common/Core/Logger.swift +++ b/phpmon/Common/Core/Logger.swift @@ -16,7 +16,8 @@ class Log { case error = 1, warning = 2, info = 3, - performance = 4 + performance = 4, + cli = 5 public func isApplicable() -> Bool { return Log.shared.verbosity.rawValue >= self.rawValue diff --git a/phpmon/Common/Shell/RealShell.swift b/phpmon/Common/Shell/RealShell.swift index 28fd203..ed69343 100644 --- a/phpmon/Common/Shell/RealShell.swift +++ b/phpmon/Common/Shell/RealShell.swift @@ -68,6 +68,7 @@ class RealShell: ShellProtocol { let task = Process() task.launchPath = self.launchPath task.arguments = ["--noprofile", "-norc", "--login", "-c", completeCommand] + return task } @@ -113,6 +114,35 @@ class RealShell: ShellProtocol { encoding: .utf8 )! + if Log.shared.verbosity == .cli { + var args = task.arguments + let last: String = "\"" + (args?.popLast() ?? "") + "\"" + let concat = [self.launchPath] + task.arguments! + [last] + let command = concat.joined(separator: " ") + var log = """ + + <~~~~~~~~~~~~~~~~~~~~~~~ + $ \(command) + + [OUT]: + \(stdOut) + """ + + if !stdErr.isEmpty { + log.append(""" + [ERR]: + \(stdErr) + """) + } + + log.append(""" + ~~~~~~~~~~~~~~~~~~~~~~~~> + + """) + + print(log) + } + return .out(stdOut, stdErr) } diff --git a/phpmon/Domain/App/AppDelegate.swift b/phpmon/Domain/App/AppDelegate.swift index 05b192e..e5df2a6 100644 --- a/phpmon/Domain/App/AppDelegate.swift +++ b/phpmon/Domain/App/AppDelegate.swift @@ -75,6 +75,11 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele Log.info("Extra verbose mode has been activated.") } + if CommandLine.arguments.contains("--cli") { + logger.verbosity = .cli + Log.info("Extra CLI mode has been activated.") + } + Log.separator(as: .info) Log.info("PHP MONITOR by Nico Verbruggen") Log.info("Version \(App.version)")