diff --git a/PHP Monitor.xcodeproj/project.pbxproj b/PHP Monitor.xcodeproj/project.pbxproj index 8241199..46c8219 100644 --- a/PHP Monitor.xcodeproj/project.pbxproj +++ b/PHP Monitor.xcodeproj/project.pbxproj @@ -28,7 +28,7 @@ C415D3B72770F294005EF286 /* Actions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C415D3B62770F294005EF286 /* Actions.swift */; }; C415D3B82770F294005EF286 /* Actions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C415D3B62770F294005EF286 /* Actions.swift */; }; C415D3E12770F34D005EF286 /* AllowedArguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = C415D3DE2770F34D005EF286 /* AllowedArguments.swift */; }; - C415D3E22770F34D005EF286 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = C415D3DF2770F34D005EF286 /* main.swift */; }; + C415D3E62770F540005EF286 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = C415D3E52770F540005EF286 /* main.swift */; }; C4188989275FE8CB001EF227 /* Filesystem.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4188988275FE8CB001EF227 /* Filesystem.swift */; }; C418898A275FE8CB001EF227 /* Filesystem.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4188988275FE8CB001EF227 /* Filesystem.swift */; }; C41C1B3722B0097F00E7CF16 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C41C1B3622B0097F00E7CF16 /* AppDelegate.swift */; }; @@ -170,7 +170,7 @@ C415D3B62770F294005EF286 /* Actions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Actions.swift; sourceTree = ""; }; C415D3D62770F341005EF286 /* phpmon-cli */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "phpmon-cli"; sourceTree = BUILT_PRODUCTS_DIR; }; C415D3DE2770F34D005EF286 /* AllowedArguments.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AllowedArguments.swift; sourceTree = ""; }; - C415D3DF2770F34D005EF286 /* main.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = main.swift; path = "../../../Desktop/phpmon-cli/main.swift"; sourceTree = ""; }; + C415D3E52770F540005EF286 /* main.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; C4188988275FE8CB001EF227 /* Filesystem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Filesystem.swift; sourceTree = ""; }; C41C1B3322B0097F00E7CF16 /* PHP Monitor.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "PHP Monitor.app"; sourceTree = BUILT_PRODUCTS_DIR; }; C41C1B3622B0097F00E7CF16 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; @@ -312,7 +312,7 @@ C415D3D72770F341005EF286 /* phpmon-cli */ = { isa = PBXGroup; children = ( - C415D3DF2770F34D005EF286 /* main.swift */, + C415D3E52770F540005EF286 /* main.swift */, C415D3DE2770F34D005EF286 /* AllowedArguments.swift */, ); path = "phpmon-cli"; @@ -675,8 +675,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + C415D3E62770F540005EF286 /* main.swift in Sources */, C415D3E12770F34D005EF286 /* AllowedArguments.swift in Sources */, - C415D3E22770F34D005EF286 /* main.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/phpmon-cli/main.swift b/phpmon-cli/main.swift index 574c395..5070216 100644 --- a/phpmon-cli/main.swift +++ b/phpmon-cli/main.swift @@ -8,5 +8,31 @@ import Foundation -print("Hello, World!") +// First, let's read the initial command line argument +print(CommandLine.arguments) + +if CommandLine.arguments.count != 3 { + print("You must enter two arguments.") + exit(1) +} + +let argument = CommandLine.arguments[1] + +if !AllowedArguments.has(argument) { + print("The supported arguments are: \(AllowedArguments.rawValues)") + exit(1) +} + +let action = AllowedArguments.init(rawValue: argument) + +switch action { +case .use: + // Read the PHP value + let version = CommandLine.arguments[2] + print("Switching to PHP \(version)...") + break +case .none: + print("Action not recognized!") + exit(1) +} diff --git a/phpmon-cli/phpmon-cli/main.swift b/phpmon-cli/phpmon-cli/main.swift deleted file mode 100644 index 86ed8e3..0000000 --- a/phpmon-cli/phpmon-cli/main.swift +++ /dev/null @@ -1,11 +0,0 @@ -// -// main.swift -// phpmon-cli -// -// Created by Nico Verbruggen on 20/12/2021. -// - -import Foundation - -print("Hello, World!") -