From 258c39bdfe08dd9fd9a38371da3c9eb2e4b99ff3 Mon Sep 17 00:00:00 2001 From: Eddy Wister Date: Wed, 15 Mar 2023 02:11:40 -0600 Subject: [PATCH 1/8] refactor -c context --- kubec-cmd/ArgsManager.swift | 38 ++++++++++++++++++++++-------------- kubec-cmd/Dirhelper.swift | 6 +++--- kubec-cmd/FilesManager.swift | 20 ++++++++++++++----- kubec-cmd/main.swift | 13 ++++-------- 4 files changed, 45 insertions(+), 32 deletions(-) diff --git a/kubec-cmd/ArgsManager.swift b/kubec-cmd/ArgsManager.swift index d7ae0fb..b7a0943 100644 --- a/kubec-cmd/ArgsManager.swift +++ b/kubec-cmd/ArgsManager.swift @@ -1,4 +1,3 @@ -// // ArgsManager.swift // kubec-cmd // @@ -7,21 +6,30 @@ import Foundation +struct Args { + var target: String = "" + var context: String = "" +} - - -func ArgsController () -> String{ - - var target = "" +func ArgsController() -> Args { + var args = Args() let arguments = CommandLine.arguments - - if arguments.contains("-t") && arguments.count > 2 - { - let targetfile = arguments[2] - target = targetfile - print("Argument 1 ↪︎ ",arguments[1]) - print("Argument 2 ↪︎ ",arguments[2]) - print("Target found ➥",targetfile) + + if let targetIndex = arguments.firstIndex(of: "-t"), arguments.count > targetIndex + 1 { + let targetFile = arguments[targetIndex + 1] + args.target = targetFile + print("Argument 1 ↪︎ ", arguments[targetIndex]) + print("Argument 2 ↪︎ ", arguments[targetIndex + 1]) + print("Target found ➥", targetFile) } - return target + + if let contextIndex = arguments.firstIndex(of: "-c"), arguments.count > contextIndex + 1 { + let context = arguments[contextIndex + 1] + args.context = context + print("Argument 3 ↪︎ ", arguments[contextIndex]) + print("Argument 4 ↪︎ ", arguments[contextIndex + 1]) + print("Context found ➥", context) + } + + return args } diff --git a/kubec-cmd/Dirhelper.swift b/kubec-cmd/Dirhelper.swift index f557c3a..df1daae 100644 --- a/kubec-cmd/Dirhelper.swift +++ b/kubec-cmd/Dirhelper.swift @@ -1,4 +1,3 @@ -// // Dirhelper.swift // kubec-cmd // @@ -7,8 +6,7 @@ import Foundation -func PrintInstructions( ) -{ +func PrintInstructions() { print("Kubec-cmd ⛴️") print("Formula ∑ : V1 ⚛️") print("🛠️---------------------------------🛠️") @@ -16,4 +14,6 @@ func PrintInstructions( ) print("🛠️---------------------------------🛠️") print("Place Target file ℹ️ : config_'subfix'") print("🛠️---------------------------------🛠️") + print("Using a specific context 📝: kubec-cmd -t 'subfix' -c 'context'") + print("🛠️---------------------------------🛠️") } diff --git a/kubec-cmd/FilesManager.swift b/kubec-cmd/FilesManager.swift index 4263d79..061034c 100644 --- a/kubec-cmd/FilesManager.swift +++ b/kubec-cmd/FilesManager.swift @@ -1,4 +1,3 @@ -// // FilesManager.swift // kubec-cmd // @@ -7,11 +6,13 @@ import Foundation - let dir = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(".kube").appendingPathComponent("bk") var _target = "" -func SearchFiles(target: String ) { +var _context = "" + +func SearchFiles(target: String, context: String) { _target = target + _context = context CreateBackUpDirectory() Makebackup() Clean() @@ -48,7 +49,6 @@ func Makebackup() { } - func Clean () { //If exist file .kube/config var exist = false @@ -66,7 +66,6 @@ func Clean () { } } - //copy file .kube/config_ to .kube/config //If exist file .kube/config @@ -87,6 +86,17 @@ func SwitcherConfig() { print("Ooops! Something went wrong: \(error)") } print("Completed ✅") + + // Cambia el contexto si se especificó + if !_context.isEmpty { + let changeContextCommand = "kubectl config use-context \(_context)" + let task = Process() + task.launchPath = "/bin/bash" + task.arguments = ["-c", changeContextCommand] + task.launch() + task.waitUntilExit() + print("Context switched to: \(_context)") + } } else { print("Target no exist ❌ " + _target ) diff --git a/kubec-cmd/main.swift b/kubec-cmd/main.swift index 6465ff6..7246630 100644 --- a/kubec-cmd/main.swift +++ b/kubec-cmd/main.swift @@ -1,4 +1,3 @@ -// // main.swift // kubec-cmd // @@ -7,21 +6,20 @@ import Foundation - let configsuffix = "config_" let kubeconfigDir = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(".kube").appendingPathComponent("config") let kubeconfig = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(".kube") PrintInstructions() -let target = ArgsController() +// Modified to handle both target and context arguments +let (target, context) = ArgsController() if String(target).isEmpty { print("Fail") } - //get files in path let fileManager = FileManager.default let enumerator:FileManager.DirectoryEnumerator = fileManager.enumerator(atPath: kubeconfig.path())! @@ -40,8 +38,5 @@ for file in enumerator { } } -SearchFiles(target: target) - - - - +// Modified to handle context argument +SearchFiles(target: target, context: context) From 9318cac0fb7299446a2bddfc5c9013cd3841fb9d Mon Sep 17 00:00:00 2001 From: Wister Date: Thu, 16 Mar 2023 02:06:11 -0600 Subject: [PATCH 2/8] Fixes --- .../xcshareddata/xcschemes/kubec-cmd.xcscheme | 97 +++++++++++++++++++ .../xcdebugger/Breakpoints_v2.xcbkptlist | 88 +++++++++++++++++ .../xcschemes/xcschememanagement.plist | 8 ++ kubec-cmd/Dirhelper.swift | 8 +- kubec-cmd/FilesManager.swift | 6 +- kubec-cmd/main.swift | 7 +- 6 files changed, 204 insertions(+), 10 deletions(-) create mode 100644 kubec-cmd.xcodeproj/xcshareddata/xcschemes/kubec-cmd.xcscheme create mode 100644 kubec-cmd.xcodeproj/xcuserdata/eddywister.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist diff --git a/kubec-cmd.xcodeproj/xcshareddata/xcschemes/kubec-cmd.xcscheme b/kubec-cmd.xcodeproj/xcshareddata/xcschemes/kubec-cmd.xcscheme new file mode 100644 index 0000000..3d1435f --- /dev/null +++ b/kubec-cmd.xcodeproj/xcshareddata/xcschemes/kubec-cmd.xcscheme @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/kubec-cmd.xcodeproj/xcuserdata/eddywister.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/kubec-cmd.xcodeproj/xcuserdata/eddywister.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..35efacf --- /dev/null +++ b/kubec-cmd.xcodeproj/xcuserdata/eddywister.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/kubec-cmd.xcodeproj/xcuserdata/eddywister.xcuserdatad/xcschemes/xcschememanagement.plist b/kubec-cmd.xcodeproj/xcuserdata/eddywister.xcuserdatad/xcschemes/xcschememanagement.plist index c35d7e4..f20226f 100644 --- a/kubec-cmd.xcodeproj/xcuserdata/eddywister.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/kubec-cmd.xcodeproj/xcuserdata/eddywister.xcuserdatad/xcschemes/xcschememanagement.plist @@ -10,5 +10,13 @@ 0 + SuppressBuildableAutocreation + + 2F030675291B0A7E00F3C62C + + primary + + + diff --git a/kubec-cmd/Dirhelper.swift b/kubec-cmd/Dirhelper.swift index df1daae..0a45afa 100644 --- a/kubec-cmd/Dirhelper.swift +++ b/kubec-cmd/Dirhelper.swift @@ -9,11 +9,11 @@ import Foundation func PrintInstructions() { print("Kubec-cmd ⛴️") print("Formula ∑ : V1 ⚛️") - print("🛠️---------------------------------🛠️") + print("🛠️---------------------------------------------------------------------------------------------------🛠️") print("Target file 🎯: kubec-cmd -t 'subfix'") - print("🛠️---------------------------------🛠️") + print("🛠️---------------------------------------------------------------------------------------------------🛠️") print("Place Target file ℹ️ : config_'subfix'") - print("🛠️---------------------------------🛠️") + print("🛠️---------------------------------------------------------------------------------------------------🛠️") print("Using a specific context 📝: kubec-cmd -t 'subfix' -c 'context'") - print("🛠️---------------------------------🛠️") + print("🛠️---------------------------------------------------------------------------------------------------🛠️") } diff --git a/kubec-cmd/FilesManager.swift b/kubec-cmd/FilesManager.swift index 061034c..84fed12 100644 --- a/kubec-cmd/FilesManager.swift +++ b/kubec-cmd/FilesManager.swift @@ -89,10 +89,10 @@ func SwitcherConfig() { // Cambia el contexto si se especificó if !_context.isEmpty { - let changeContextCommand = "kubectl config use-context \(_context)" + let changeContextCommand = "config use-context \(_context)" let task = Process() - task.launchPath = "/bin/bash" - task.arguments = ["-c", changeContextCommand] + task.launchPath = "/opt/homebrew/bin/kubectl" + task.arguments = [changeContextCommand] task.launch() task.waitUntilExit() print("Context switched to: \(_context)") diff --git a/kubec-cmd/main.swift b/kubec-cmd/main.swift index 7246630..5b13649 100644 --- a/kubec-cmd/main.swift +++ b/kubec-cmd/main.swift @@ -13,10 +13,11 @@ let kubeconfig = FileManager.default.homeDirectoryForCurrentUser.appendingPathCo PrintInstructions() // Modified to handle both target and context arguments -let (target, context) = ArgsController() +let args = ArgsController() +let target = args.target +let context = args.context -if String(target).isEmpty -{ +if target.isEmpty { print("Fail") } From 8e7efdb19e7fc831ac56208a5459464211eb05b5 Mon Sep 17 00:00:00 2001 From: Wister Date: Fri, 28 Jul 2023 13:59:17 -0600 Subject: [PATCH 3/8] First Draft Kubec-cmd --list --- kubec-cmd.xcodeproj/project.pbxproj | 453 +++++++++++++++++- .../xcshareddata/xcschemes/kubec-cmd.xcscheme | 23 +- .../xcdebugger/Breakpoints_v2.xcbkptlist | 145 +++++- .../xcschemes/xcschememanagement.plist | 18 + kubec-cmd/ArgsManager.swift | 22 +- kubec-cmd/Dirhelper.swift | 1 + kubec-cmd/FilesManager.swift | 20 + kubec-cmdTests/FilesManagerTests.swift | 0 .../AccentColor.colorset/Contents.json | 11 + .../AppIcon.appiconset/Contents.json | 63 +++ linux/Assets.xcassets/Contents.json | 6 + linux/ContentView.swift | 90 ++++ linux/Persistence.swift | 56 +++ .../Preview Assets.xcassets/Contents.json | 6 + linux/linux.entitlements | 10 + linux/linux.xcdatamodeld/.xccurrentversion | 8 + .../linux.xcdatamodel/contents | 9 + linux/linuxApp.swift | 20 + linuxTests/linuxTests.swift | 35 ++ linuxUITests/linuxUITests.swift | 41 ++ linuxUITests/linuxUITestsLaunchTests.swift | 32 ++ 21 files changed, 1040 insertions(+), 29 deletions(-) create mode 100644 kubec-cmdTests/FilesManagerTests.swift create mode 100644 linux/Assets.xcassets/AccentColor.colorset/Contents.json create mode 100644 linux/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 linux/Assets.xcassets/Contents.json create mode 100644 linux/ContentView.swift create mode 100644 linux/Persistence.swift create mode 100644 linux/Preview Content/Preview Assets.xcassets/Contents.json create mode 100644 linux/linux.entitlements create mode 100644 linux/linux.xcdatamodeld/.xccurrentversion create mode 100644 linux/linux.xcdatamodeld/linux.xcdatamodel/contents create mode 100644 linux/linuxApp.swift create mode 100644 linuxTests/linuxTests.swift create mode 100644 linuxUITests/linuxUITests.swift create mode 100644 linuxUITests/linuxUITestsLaunchTests.swift diff --git a/kubec-cmd.xcodeproj/project.pbxproj b/kubec-cmd.xcodeproj/project.pbxproj index e6685e0..9ee3992 100644 --- a/kubec-cmd.xcodeproj/project.pbxproj +++ b/kubec-cmd.xcodeproj/project.pbxproj @@ -7,12 +7,38 @@ objects = { /* Begin PBXBuildFile section */ + 2F0235762A531F8F00A835C2 /* linuxApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F0235752A531F8F00A835C2 /* linuxApp.swift */; }; + 2F0235782A531F8F00A835C2 /* Persistence.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F0235772A531F8F00A835C2 /* Persistence.swift */; }; + 2F02357B2A531F8F00A835C2 /* linux.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 2F0235792A531F8F00A835C2 /* linux.xcdatamodeld */; }; + 2F02357D2A531F8F00A835C2 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F02357C2A531F8F00A835C2 /* ContentView.swift */; }; + 2F02357F2A531F9000A835C2 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2F02357E2A531F9000A835C2 /* Assets.xcassets */; }; + 2F0235832A531F9000A835C2 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2F0235822A531F9000A835C2 /* Preview Assets.xcassets */; }; + 2F02358D2A531F9000A835C2 /* linuxTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F02358C2A531F9000A835C2 /* linuxTests.swift */; }; + 2F0235972A531F9000A835C2 /* linuxUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F0235962A531F9000A835C2 /* linuxUITests.swift */; }; + 2F0235992A531F9000A835C2 /* linuxUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F0235982A531F9000A835C2 /* linuxUITestsLaunchTests.swift */; }; 2F03067A291B0A7E00F3C62C /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F030679291B0A7E00F3C62C /* main.swift */; }; 2F2D0CB729319FE0005FDD2F /* Dirhelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F2D0CB629319FE0005FDD2F /* Dirhelper.swift */; }; 2F2D0CB92931B341005FDD2F /* ArgsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F2D0CB82931B341005FDD2F /* ArgsManager.swift */; }; 2F2D0CBB2931C2D7005FDD2F /* FilesManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F2D0CBA2931C2D7005FDD2F /* FilesManager.swift */; }; /* End PBXBuildFile section */ +/* Begin PBXContainerItemProxy section */ + 2F0235892A531F9000A835C2 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 2F03066E291B0A7E00F3C62C /* Project object */; + proxyType = 1; + remoteGlobalIDString = 2F0235722A531F8F00A835C2; + remoteInfo = linux; + }; + 2F0235932A531F9000A835C2 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 2F03066E291B0A7E00F3C62C /* Project object */; + proxyType = 1; + remoteGlobalIDString = 2F0235722A531F8F00A835C2; + remoteInfo = linux; + }; +/* End PBXContainerItemProxy section */ + /* Begin PBXCopyFilesBuildPhase section */ 2F030674291B0A7E00F3C62C /* CopyFiles */ = { isa = PBXCopyFilesBuildPhase; @@ -26,6 +52,19 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 2F0235732A531F8F00A835C2 /* linux.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = linux.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 2F0235752A531F8F00A835C2 /* linuxApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = linuxApp.swift; sourceTree = ""; }; + 2F0235772A531F8F00A835C2 /* Persistence.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Persistence.swift; sourceTree = ""; }; + 2F02357A2A531F8F00A835C2 /* linux.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = linux.xcdatamodel; sourceTree = ""; }; + 2F02357C2A531F8F00A835C2 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; + 2F02357E2A531F9000A835C2 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 2F0235802A531F9000A835C2 /* linux.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = linux.entitlements; sourceTree = ""; }; + 2F0235822A531F9000A835C2 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; + 2F0235882A531F9000A835C2 /* linuxTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = linuxTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 2F02358C2A531F9000A835C2 /* linuxTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = linuxTests.swift; sourceTree = ""; }; + 2F0235922A531F9000A835C2 /* linuxUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = linuxUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 2F0235962A531F9000A835C2 /* linuxUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = linuxUITests.swift; sourceTree = ""; }; + 2F0235982A531F9000A835C2 /* linuxUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = linuxUITestsLaunchTests.swift; sourceTree = ""; }; 2F030676291B0A7E00F3C62C /* kubec-cmd */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "kubec-cmd"; sourceTree = BUILT_PRODUCTS_DIR; }; 2F030679291B0A7E00F3C62C /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; 2F2D0CB629319FE0005FDD2F /* Dirhelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Dirhelper.swift; path = "kubec-cmd/Dirhelper.swift"; sourceTree = ""; }; @@ -34,6 +73,27 @@ /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ + 2F0235702A531F8F00A835C2 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 2F0235852A531F9000A835C2 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 2F02358F2A531F9000A835C2 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; 2F030673291B0A7E00F3C62C /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -44,11 +104,53 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 2F0235742A531F8F00A835C2 /* linux */ = { + isa = PBXGroup; + children = ( + 2F0235752A531F8F00A835C2 /* linuxApp.swift */, + 2F0235772A531F8F00A835C2 /* Persistence.swift */, + 2F02357C2A531F8F00A835C2 /* ContentView.swift */, + 2F02357E2A531F9000A835C2 /* Assets.xcassets */, + 2F0235802A531F9000A835C2 /* linux.entitlements */, + 2F0235792A531F8F00A835C2 /* linux.xcdatamodeld */, + 2F0235812A531F9000A835C2 /* Preview Content */, + ); + path = linux; + sourceTree = ""; + }; + 2F0235812A531F9000A835C2 /* Preview Content */ = { + isa = PBXGroup; + children = ( + 2F0235822A531F9000A835C2 /* Preview Assets.xcassets */, + ); + path = "Preview Content"; + sourceTree = ""; + }; + 2F02358B2A531F9000A835C2 /* linuxTests */ = { + isa = PBXGroup; + children = ( + 2F02358C2A531F9000A835C2 /* linuxTests.swift */, + ); + path = linuxTests; + sourceTree = ""; + }; + 2F0235952A531F9000A835C2 /* linuxUITests */ = { + isa = PBXGroup; + children = ( + 2F0235962A531F9000A835C2 /* linuxUITests.swift */, + 2F0235982A531F9000A835C2 /* linuxUITestsLaunchTests.swift */, + ); + path = linuxUITests; + sourceTree = ""; + }; 2F03066D291B0A7E00F3C62C = { isa = PBXGroup; children = ( 2F2D0CB629319FE0005FDD2F /* Dirhelper.swift */, 2F030678291B0A7E00F3C62C /* kubec-cmd */, + 2F0235742A531F8F00A835C2 /* linux */, + 2F02358B2A531F9000A835C2 /* linuxTests */, + 2F0235952A531F9000A835C2 /* linuxUITests */, 2F030677291B0A7E00F3C62C /* Products */, ); sourceTree = ""; @@ -57,6 +159,9 @@ isa = PBXGroup; children = ( 2F030676291B0A7E00F3C62C /* kubec-cmd */, + 2F0235732A531F8F00A835C2 /* linux.app */, + 2F0235882A531F9000A835C2 /* linuxTests.xctest */, + 2F0235922A531F9000A835C2 /* linuxUITests.xctest */, ); name = Products; sourceTree = ""; @@ -74,6 +179,59 @@ /* End PBXGroup section */ /* Begin PBXNativeTarget section */ + 2F0235722A531F8F00A835C2 /* linux */ = { + isa = PBXNativeTarget; + buildConfigurationList = 2F02359A2A531F9000A835C2 /* Build configuration list for PBXNativeTarget "linux" */; + buildPhases = ( + 2F02356F2A531F8F00A835C2 /* Sources */, + 2F0235702A531F8F00A835C2 /* Frameworks */, + 2F0235712A531F8F00A835C2 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = linux; + productName = linux; + productReference = 2F0235732A531F8F00A835C2 /* linux.app */; + productType = "com.apple.product-type.application"; + }; + 2F0235872A531F9000A835C2 /* linuxTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 2F02359D2A531F9000A835C2 /* Build configuration list for PBXNativeTarget "linuxTests" */; + buildPhases = ( + 2F0235842A531F9000A835C2 /* Sources */, + 2F0235852A531F9000A835C2 /* Frameworks */, + 2F0235862A531F9000A835C2 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 2F02358A2A531F9000A835C2 /* PBXTargetDependency */, + ); + name = linuxTests; + productName = linuxTests; + productReference = 2F0235882A531F9000A835C2 /* linuxTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; + 2F0235912A531F9000A835C2 /* linuxUITests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 2F0235A02A531F9000A835C2 /* Build configuration list for PBXNativeTarget "linuxUITests" */; + buildPhases = ( + 2F02358E2A531F9000A835C2 /* Sources */, + 2F02358F2A531F9000A835C2 /* Frameworks */, + 2F0235902A531F9000A835C2 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 2F0235942A531F9000A835C2 /* PBXTargetDependency */, + ); + name = linuxUITests; + productName = linuxUITests; + productReference = 2F0235922A531F9000A835C2 /* linuxUITests.xctest */; + productType = "com.apple.product-type.bundle.ui-testing"; + }; 2F030675291B0A7E00F3C62C /* kubec-cmd */ = { isa = PBXNativeTarget; buildConfigurationList = 2F03067D291B0A7E00F3C62C /* Build configuration list for PBXNativeTarget "kubec-cmd" */; @@ -98,9 +256,20 @@ isa = PBXProject; attributes = { BuildIndependentTargetsInParallel = 1; - LastSwiftUpdateCheck = 1410; + LastSwiftUpdateCheck = 1430; LastUpgradeCheck = 1410; TargetAttributes = { + 2F0235722A531F8F00A835C2 = { + CreatedOnToolsVersion = 14.3.1; + }; + 2F0235872A531F9000A835C2 = { + CreatedOnToolsVersion = 14.3.1; + TestTargetID = 2F0235722A531F8F00A835C2; + }; + 2F0235912A531F9000A835C2 = { + CreatedOnToolsVersion = 14.3.1; + TestTargetID = 2F0235722A531F8F00A835C2; + }; 2F030675291B0A7E00F3C62C = { CreatedOnToolsVersion = 14.1; }; @@ -120,11 +289,68 @@ projectRoot = ""; targets = ( 2F030675291B0A7E00F3C62C /* kubec-cmd */, + 2F0235722A531F8F00A835C2 /* linux */, + 2F0235872A531F9000A835C2 /* linuxTests */, + 2F0235912A531F9000A835C2 /* linuxUITests */, ); }; /* End PBXProject section */ +/* Begin PBXResourcesBuildPhase section */ + 2F0235712A531F8F00A835C2 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 2F0235832A531F9000A835C2 /* Preview Assets.xcassets in Resources */, + 2F02357F2A531F9000A835C2 /* Assets.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 2F0235862A531F9000A835C2 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 2F0235902A531F9000A835C2 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ + 2F02356F2A531F8F00A835C2 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 2F0235762A531F8F00A835C2 /* linuxApp.swift in Sources */, + 2F0235782A531F8F00A835C2 /* Persistence.swift in Sources */, + 2F02357D2A531F8F00A835C2 /* ContentView.swift in Sources */, + 2F02357B2A531F8F00A835C2 /* linux.xcdatamodeld in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 2F0235842A531F9000A835C2 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 2F02358D2A531F9000A835C2 /* linuxTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 2F02358E2A531F9000A835C2 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 2F0235972A531F9000A835C2 /* linuxUITests.swift in Sources */, + 2F0235992A531F9000A835C2 /* linuxUITestsLaunchTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 2F030672291B0A7E00F3C62C /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -138,7 +364,190 @@ }; /* End PBXSourcesBuildPhase section */ +/* Begin PBXTargetDependency section */ + 2F02358A2A531F9000A835C2 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 2F0235722A531F8F00A835C2 /* linux */; + targetProxy = 2F0235892A531F9000A835C2 /* PBXContainerItemProxy */; + }; + 2F0235942A531F9000A835C2 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 2F0235722A531F8F00A835C2 /* linux */; + targetProxy = 2F0235932A531F9000A835C2 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + /* Begin XCBuildConfiguration section */ + 2F02359B2A531F9000A835C2 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_ENTITLEMENTS = linux/linux.entitlements; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_ASSET_PATHS = "\"linux/Preview Content\""; + DEVELOPMENT_TEAM = 3HC7295HS9; + ENABLE_HARDENED_RUNTIME = YES; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; + "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; + "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; + "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES; + "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES; + "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphonesimulator*]" = YES; + "INFOPLIST_KEY_UIStatusBarStyle[sdk=iphoneos*]" = UIStatusBarStyleDefault; + "INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + IPHONEOS_DEPLOYMENT_TARGET = 16.4; + LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; + "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 13.3; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = Wister.linux; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = auto; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 2F02359C2A531F9000A835C2 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_ENTITLEMENTS = linux/linux.entitlements; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_ASSET_PATHS = "\"linux/Preview Content\""; + DEVELOPMENT_TEAM = 3HC7295HS9; + ENABLE_HARDENED_RUNTIME = YES; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; + "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; + "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; + "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES; + "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES; + "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphonesimulator*]" = YES; + "INFOPLIST_KEY_UIStatusBarStyle[sdk=iphoneos*]" = UIStatusBarStyleDefault; + "INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + IPHONEOS_DEPLOYMENT_TARGET = 16.4; + LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; + "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 13.3; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = Wister.linux; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = auto; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; + 2F02359E2A531F9000A835C2 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = 3HC7295HS9; + GENERATE_INFOPLIST_FILE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 16.4; + MACOSX_DEPLOYMENT_TARGET = 13.3; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = Wister.linuxTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = auto; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx"; + SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/linux.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/linux"; + }; + name = Debug; + }; + 2F02359F2A531F9000A835C2 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = 3HC7295HS9; + GENERATE_INFOPLIST_FILE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 16.4; + MACOSX_DEPLOYMENT_TARGET = 13.3; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = Wister.linuxTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = auto; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx"; + SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/linux.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/linux"; + }; + name = Release; + }; + 2F0235A12A531F9000A835C2 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALLOW_TARGET_PLATFORM_SPECIALIZATION = YES; + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = 3HC7295HS9; + GENERATE_INFOPLIST_FILE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 16.4; + MACOSX_DEPLOYMENT_TARGET = 13.3; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = Wister.linuxUITests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = auto; + SUPPORTED_PLATFORMS = "watchsimulator watchos macosx iphonesimulator iphoneos driverkit appletvsimulator appletvos"; + SUPPORTS_MACCATALYST = YES; + SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_TARGET_NAME = linux; + }; + name = Debug; + }; + 2F0235A22A531F9000A835C2 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALLOW_TARGET_PLATFORM_SPECIALIZATION = YES; + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = 3HC7295HS9; + GENERATE_INFOPLIST_FILE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 16.4; + MACOSX_DEPLOYMENT_TARGET = 13.3; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = Wister.linuxUITests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = auto; + SUPPORTED_PLATFORMS = "watchsimulator watchos macosx iphonesimulator iphoneos driverkit appletvsimulator appletvos"; + SUPPORTS_MACCATALYST = YES; + SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_TARGET_NAME = linux; + }; + name = Release; + }; 2F03067B291B0A7E00F3C62C /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -192,6 +601,7 @@ MACOSX_DEPLOYMENT_TARGET = 13.0; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; + NEW_SETTING = ""; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; @@ -246,6 +656,7 @@ MACOSX_DEPLOYMENT_TARGET = 13.0; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; + NEW_SETTING = ""; SDKROOT = macosx; SWIFT_COMPILATION_MODE = wholemodule; SWIFT_OPTIMIZATION_LEVEL = "-O"; @@ -277,6 +688,33 @@ /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ + 2F02359A2A531F9000A835C2 /* Build configuration list for PBXNativeTarget "linux" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 2F02359B2A531F9000A835C2 /* Debug */, + 2F02359C2A531F9000A835C2 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 2F02359D2A531F9000A835C2 /* Build configuration list for PBXNativeTarget "linuxTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 2F02359E2A531F9000A835C2 /* Debug */, + 2F02359F2A531F9000A835C2 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 2F0235A02A531F9000A835C2 /* Build configuration list for PBXNativeTarget "linuxUITests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 2F0235A12A531F9000A835C2 /* Debug */, + 2F0235A22A531F9000A835C2 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; 2F030671291B0A7E00F3C62C /* Build configuration list for PBXProject "kubec-cmd" */ = { isa = XCConfigurationList; buildConfigurations = ( @@ -296,6 +734,19 @@ defaultConfigurationName = Release; }; /* End XCConfigurationList section */ + +/* Begin XCVersionGroup section */ + 2F0235792A531F8F00A835C2 /* linux.xcdatamodeld */ = { + isa = XCVersionGroup; + children = ( + 2F02357A2A531F8F00A835C2 /* linux.xcdatamodel */, + ); + currentVersion = 2F02357A2A531F8F00A835C2 /* linux.xcdatamodel */; + path = linux.xcdatamodeld; + sourceTree = ""; + versionGroupType = wrapper.xcdatamodel; + }; +/* End XCVersionGroup section */ }; rootObject = 2F03066E291B0A7E00F3C62C /* Project object */; } diff --git a/kubec-cmd.xcodeproj/xcshareddata/xcschemes/kubec-cmd.xcscheme b/kubec-cmd.xcodeproj/xcshareddata/xcschemes/kubec-cmd.xcscheme index 3d1435f..af49198 100644 --- a/kubec-cmd.xcodeproj/xcshareddata/xcschemes/kubec-cmd.xcscheme +++ b/kubec-cmd.xcodeproj/xcshareddata/xcschemes/kubec-cmd.xcscheme @@ -1,7 +1,7 @@ + LastUpgradeVersion = "1430" + version = "1.7"> @@ -26,9 +26,8 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - shouldUseLaunchSchemeArgsEnv = "YES"> - - + shouldUseLaunchSchemeArgsEnv = "YES" + shouldAutocreateTestPlan = "YES"> - - - - - - diff --git a/kubec-cmd.xcodeproj/xcuserdata/eddywister.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/kubec-cmd.xcodeproj/xcuserdata/eddywister.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 35efacf..40009cb 100644 --- a/kubec-cmd.xcodeproj/xcuserdata/eddywister.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/kubec-cmd.xcodeproj/xcuserdata/eddywister.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -72,7 +72,7 @@ BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint"> + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/kubec-cmd.xcodeproj/xcuserdata/eddywister.xcuserdatad/xcschemes/xcschememanagement.plist b/kubec-cmd.xcodeproj/xcuserdata/eddywister.xcuserdatad/xcschemes/xcschememanagement.plist index f20226f..7d4e6cb 100644 --- a/kubec-cmd.xcodeproj/xcuserdata/eddywister.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/kubec-cmd.xcodeproj/xcuserdata/eddywister.xcuserdatad/xcschemes/xcschememanagement.plist @@ -9,6 +9,24 @@ orderHint 0 + linux.xcscheme_^#shared#^_ + + orderHint + 1 + + unix.xcscheme_^#shared#^_ + + orderHint + 0 + + + SuppressBuildableAutocreation + + 2F030675291B0A7E00F3C62C + + primary + + SuppressBuildableAutocreation diff --git a/kubec-cmd/ArgsManager.swift b/kubec-cmd/ArgsManager.swift index b7a0943..5f23fdc 100644 --- a/kubec-cmd/ArgsManager.swift +++ b/kubec-cmd/ArgsManager.swift @@ -22,14 +22,20 @@ func ArgsController() -> Args { print("Argument 2 ↪︎ ", arguments[targetIndex + 1]) print("Target found ➥", targetFile) } - - if let contextIndex = arguments.firstIndex(of: "-c"), arguments.count > contextIndex + 1 { - let context = arguments[contextIndex + 1] - args.context = context - print("Argument 3 ↪︎ ", arguments[contextIndex]) - print("Argument 4 ↪︎ ", arguments[contextIndex + 1]) - print("Context found ➥", context) + //new arg --list using this method listfilesinpath() + else if arguments.contains("--list") + { + let files = listfilesinpath() + print("List of files in path: ",kubeconfig) + for file in files { + print(file) + } + } + else + { + print("No target file found") + PrintInstructions() } - return args + return target } diff --git a/kubec-cmd/Dirhelper.swift b/kubec-cmd/Dirhelper.swift index 0a45afa..580a373 100644 --- a/kubec-cmd/Dirhelper.swift +++ b/kubec-cmd/Dirhelper.swift @@ -17,3 +17,4 @@ func PrintInstructions() { print("Using a specific context 📝: kubec-cmd -t 'subfix' -c 'context'") print("🛠️---------------------------------------------------------------------------------------------------🛠️") } + diff --git a/kubec-cmd/FilesManager.swift b/kubec-cmd/FilesManager.swift index 84fed12..b86e446 100644 --- a/kubec-cmd/FilesManager.swift +++ b/kubec-cmd/FilesManager.swift @@ -102,3 +102,23 @@ func SwitcherConfig() { print("Target no exist ❌ " + _target ) } } + +//list all config files in path +func listfilesinpath () -> [String] +{ + let home = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(".kube").path(); + let fileManager = FileManager.default + let enumerator:FileManager.DirectoryEnumerator = fileManager.enumerator(atPath: home)! + var ConfigFound = [String]() + for file in enumerator { + if let file = file as? String { + if file.contains(configsuffix) { +// if !file.contains("bk") && !file.contains(".back") && !file.contains(".0") && !file.contains(".1") && !file.contains(".2") && !file.contains(".3") { + if !file.contains("bk") && !file.contains(".back") && file.contains("config_") { + ConfigFound.append(file) + } + } + } + } + return ConfigFound +} diff --git a/kubec-cmdTests/FilesManagerTests.swift b/kubec-cmdTests/FilesManagerTests.swift new file mode 100644 index 0000000..e69de29 diff --git a/linux/Assets.xcassets/AccentColor.colorset/Contents.json b/linux/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 0000000..eb87897 --- /dev/null +++ b/linux/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/linux/Assets.xcassets/AppIcon.appiconset/Contents.json b/linux/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..532cd72 --- /dev/null +++ b/linux/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,63 @@ +{ + "images" : [ + { + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "16x16" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "16x16" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "32x32" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "32x32" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "128x128" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "128x128" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "256x256" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "256x256" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "512x512" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "512x512" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/linux/Assets.xcassets/Contents.json b/linux/Assets.xcassets/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/linux/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/linux/ContentView.swift b/linux/ContentView.swift new file mode 100644 index 0000000..92efbf4 --- /dev/null +++ b/linux/ContentView.swift @@ -0,0 +1,90 @@ +// +// ContentView.swift +// linux +// +// Created by Eddy Wister on 03/07/23. +// + +import SwiftUI +import CoreData + +struct ContentView: View { + @Environment(\.managedObjectContext) private var viewContext + + @FetchRequest( + sortDescriptors: [NSSortDescriptor(keyPath: \Item.timestamp, ascending: true)], + animation: .default) + private var items: FetchedResults + + var body: some View { + NavigationView { + List { + ForEach(items) { item in + NavigationLink { + Text("Item at \(item.timestamp!, formatter: itemFormatter)") + } label: { + Text(item.timestamp!, formatter: itemFormatter) + } + } + .onDelete(perform: deleteItems) + } + .toolbar { +#if os(iOS) + ToolbarItem(placement: .navigationBarTrailing) { + EditButton() + } +#endif + ToolbarItem { + Button(action: addItem) { + Label("Add Item", systemImage: "plus") + } + } + } + Text("Select an item") + } + } + + private func addItem() { + withAnimation { + let newItem = Item(context: viewContext) + newItem.timestamp = Date() + + do { + try viewContext.save() + } catch { + // Replace this implementation with code to handle the error appropriately. + // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. + let nsError = error as NSError + fatalError("Unresolved error \(nsError), \(nsError.userInfo)") + } + } + } + + private func deleteItems(offsets: IndexSet) { + withAnimation { + offsets.map { items[$0] }.forEach(viewContext.delete) + + do { + try viewContext.save() + } catch { + // Replace this implementation with code to handle the error appropriately. + // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. + let nsError = error as NSError + fatalError("Unresolved error \(nsError), \(nsError.userInfo)") + } + } + } +} + +private let itemFormatter: DateFormatter = { + let formatter = DateFormatter() + formatter.dateStyle = .short + formatter.timeStyle = .medium + return formatter +}() + +struct ContentView_Previews: PreviewProvider { + static var previews: some View { + ContentView().environment(\.managedObjectContext, PersistenceController.preview.container.viewContext) + } +} diff --git a/linux/Persistence.swift b/linux/Persistence.swift new file mode 100644 index 0000000..25529c9 --- /dev/null +++ b/linux/Persistence.swift @@ -0,0 +1,56 @@ +// +// Persistence.swift +// linux +// +// Created by Eddy Wister on 03/07/23. +// + +import CoreData + +struct PersistenceController { + static let shared = PersistenceController() + + static var preview: PersistenceController = { + let result = PersistenceController(inMemory: true) + let viewContext = result.container.viewContext + for _ in 0..<10 { + let newItem = Item(context: viewContext) + newItem.timestamp = Date() + } + do { + try viewContext.save() + } catch { + // Replace this implementation with code to handle the error appropriately. + // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. + let nsError = error as NSError + fatalError("Unresolved error \(nsError), \(nsError.userInfo)") + } + return result + }() + + let container: NSPersistentContainer + + init(inMemory: Bool = false) { + container = NSPersistentContainer(name: "linux") + if inMemory { + container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: "/dev/null") + } + container.loadPersistentStores(completionHandler: { (storeDescription, error) in + if let error = error as NSError? { + // Replace this implementation with code to handle the error appropriately. + // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. + + /* + Typical reasons for an error here include: + * The parent directory does not exist, cannot be created, or disallows writing. + * The persistent store is not accessible, due to permissions or data protection when the device is locked. + * The device is out of space. + * The store could not be migrated to the current model version. + Check the error message to determine what the actual problem was. + */ + fatalError("Unresolved error \(error), \(error.userInfo)") + } + }) + container.viewContext.automaticallyMergesChangesFromParent = true + } +} diff --git a/linux/Preview Content/Preview Assets.xcassets/Contents.json b/linux/Preview Content/Preview Assets.xcassets/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/linux/Preview Content/Preview Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/linux/linux.entitlements b/linux/linux.entitlements new file mode 100644 index 0000000..f2ef3ae --- /dev/null +++ b/linux/linux.entitlements @@ -0,0 +1,10 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.files.user-selected.read-only + + + diff --git a/linux/linux.xcdatamodeld/.xccurrentversion b/linux/linux.xcdatamodeld/.xccurrentversion new file mode 100644 index 0000000..997809e --- /dev/null +++ b/linux/linux.xcdatamodeld/.xccurrentversion @@ -0,0 +1,8 @@ + + + + + _XCCurrentVersionName + linux.xcdatamodel + + diff --git a/linux/linux.xcdatamodeld/linux.xcdatamodel/contents b/linux/linux.xcdatamodeld/linux.xcdatamodel/contents new file mode 100644 index 0000000..9ed2921 --- /dev/null +++ b/linux/linux.xcdatamodeld/linux.xcdatamodel/contents @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/linux/linuxApp.swift b/linux/linuxApp.swift new file mode 100644 index 0000000..3870426 --- /dev/null +++ b/linux/linuxApp.swift @@ -0,0 +1,20 @@ +// +// linuxApp.swift +// linux +// +// Created by Eddy Wister on 03/07/23. +// + +import SwiftUI + +@main +struct linuxApp: App { + let persistenceController = PersistenceController.shared + + var body: some Scene { + WindowGroup { + ContentView() + .environment(\.managedObjectContext, persistenceController.container.viewContext) + } + } +} diff --git a/linuxTests/linuxTests.swift b/linuxTests/linuxTests.swift new file mode 100644 index 0000000..5682800 --- /dev/null +++ b/linuxTests/linuxTests.swift @@ -0,0 +1,35 @@ +// +// linuxTests.swift +// linuxTests +// +// Created by Eddy Wister on 03/07/23. +// + +import XCTest + +final class linuxTests: XCTestCase { + + override func setUpWithError() throws { + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDownWithError() throws { + // Put teardown code here. This method is called after the invocation of each test method in the class. + } + + func testExample() throws { + // This is an example of a functional test case. + // Use XCTAssert and related functions to verify your tests produce the correct results. + // Any test you write for XCTest can be annotated as throws and async. + // Mark your test throws to produce an unexpected failure when your test encounters an uncaught error. + // Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards. + } + + func testPerformanceExample() throws { + // This is an example of a performance test case. + measure { + // Put the code you want to measure the time of here. + } + } + +} diff --git a/linuxUITests/linuxUITests.swift b/linuxUITests/linuxUITests.swift new file mode 100644 index 0000000..c8908f5 --- /dev/null +++ b/linuxUITests/linuxUITests.swift @@ -0,0 +1,41 @@ +// +// linuxUITests.swift +// linuxUITests +// +// Created by Eddy Wister on 03/07/23. +// + +import XCTest + +final class linuxUITests: XCTestCase { + + override func setUpWithError() throws { + // Put setup code here. This method is called before the invocation of each test method in the class. + + // In UI tests it is usually best to stop immediately when a failure occurs. + continueAfterFailure = false + + // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. + } + + override func tearDownWithError() throws { + // Put teardown code here. This method is called after the invocation of each test method in the class. + } + + func testExample() throws { + // UI tests must launch the application that they test. + let app = XCUIApplication() + app.launch() + + // Use XCTAssert and related functions to verify your tests produce the correct results. + } + + func testLaunchPerformance() throws { + if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 7.0, *) { + // This measures how long it takes to launch your application. + measure(metrics: [XCTApplicationLaunchMetric()]) { + XCUIApplication().launch() + } + } + } +} diff --git a/linuxUITests/linuxUITestsLaunchTests.swift b/linuxUITests/linuxUITestsLaunchTests.swift new file mode 100644 index 0000000..2b31e7a --- /dev/null +++ b/linuxUITests/linuxUITestsLaunchTests.swift @@ -0,0 +1,32 @@ +// +// linuxUITestsLaunchTests.swift +// linuxUITests +// +// Created by Eddy Wister on 03/07/23. +// + +import XCTest + +final class linuxUITestsLaunchTests: XCTestCase { + + override class var runsForEachTargetApplicationUIConfiguration: Bool { + true + } + + override func setUpWithError() throws { + continueAfterFailure = false + } + + func testLaunch() throws { + let app = XCUIApplication() + app.launch() + + // Insert steps here to perform after app launch but before taking a screenshot, + // such as logging into a test account or navigating somewhere in the app + + let attachment = XCTAttachment(screenshot: app.screenshot()) + attachment.name = "Launch Screen" + attachment.lifetime = .keepAlways + add(attachment) + } +} From 3e5c9d48cc99a4a405331ee5e6db667b04d51c47 Mon Sep 17 00:00:00 2001 From: Wister Date: Fri, 28 Jul 2023 14:11:26 -0600 Subject: [PATCH 4/8] Fix Schemes --- kubec-cmd.xcodeproj/project.pbxproj | 87 ------------------ .../xcschemes/kubec-cmd --list.xcscheme | 84 +++++++++++++++++ .../xcschemes/kubec-cmd -t.xcscheme | 88 ++++++++++++++++++ .../xcschemes/xcschememanagement.plist | 30 +++++-- kubec-cmd/ArgsManager.swift | 2 +- kubec-cmd/FilesManager.swift | 1 - .../AccentColor.colorset/Contents.json | 11 --- .../AppIcon.appiconset/Contents.json | 63 ------------- linux/Assets.xcassets/Contents.json | 6 -- linux/ContentView.swift | 90 ------------------- linux/Persistence.swift | 56 ------------ .../Preview Assets.xcassets/Contents.json | 6 -- linux/linux.entitlements | 10 --- linux/linux.xcdatamodeld/.xccurrentversion | 5 +- linux/linuxApp.swift | 20 ----- linuxTests/linuxTests.swift | 35 -------- linuxUITests/linuxUITests.swift | 41 --------- linuxUITests/linuxUITestsLaunchTests.swift | 32 ------- 18 files changed, 196 insertions(+), 471 deletions(-) create mode 100644 kubec-cmd.xcodeproj/xcshareddata/xcschemes/kubec-cmd --list.xcscheme create mode 100644 kubec-cmd.xcodeproj/xcuserdata/eddywister.xcuserdatad/xcschemes/kubec-cmd -t.xcscheme delete mode 100644 linux/Assets.xcassets/AccentColor.colorset/Contents.json delete mode 100644 linux/Assets.xcassets/AppIcon.appiconset/Contents.json delete mode 100644 linux/Assets.xcassets/Contents.json delete mode 100644 linux/ContentView.swift delete mode 100644 linux/Persistence.swift delete mode 100644 linux/Preview Content/Preview Assets.xcassets/Contents.json delete mode 100644 linux/linux.entitlements delete mode 100644 linux/linuxApp.swift delete mode 100644 linuxTests/linuxTests.swift delete mode 100644 linuxUITests/linuxUITests.swift delete mode 100644 linuxUITests/linuxUITestsLaunchTests.swift diff --git a/kubec-cmd.xcodeproj/project.pbxproj b/kubec-cmd.xcodeproj/project.pbxproj index 9ee3992..0401887 100644 --- a/kubec-cmd.xcodeproj/project.pbxproj +++ b/kubec-cmd.xcodeproj/project.pbxproj @@ -7,15 +7,6 @@ objects = { /* Begin PBXBuildFile section */ - 2F0235762A531F8F00A835C2 /* linuxApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F0235752A531F8F00A835C2 /* linuxApp.swift */; }; - 2F0235782A531F8F00A835C2 /* Persistence.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F0235772A531F8F00A835C2 /* Persistence.swift */; }; - 2F02357B2A531F8F00A835C2 /* linux.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 2F0235792A531F8F00A835C2 /* linux.xcdatamodeld */; }; - 2F02357D2A531F8F00A835C2 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F02357C2A531F8F00A835C2 /* ContentView.swift */; }; - 2F02357F2A531F9000A835C2 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2F02357E2A531F9000A835C2 /* Assets.xcassets */; }; - 2F0235832A531F9000A835C2 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2F0235822A531F9000A835C2 /* Preview Assets.xcassets */; }; - 2F02358D2A531F9000A835C2 /* linuxTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F02358C2A531F9000A835C2 /* linuxTests.swift */; }; - 2F0235972A531F9000A835C2 /* linuxUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F0235962A531F9000A835C2 /* linuxUITests.swift */; }; - 2F0235992A531F9000A835C2 /* linuxUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F0235982A531F9000A835C2 /* linuxUITestsLaunchTests.swift */; }; 2F03067A291B0A7E00F3C62C /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F030679291B0A7E00F3C62C /* main.swift */; }; 2F2D0CB729319FE0005FDD2F /* Dirhelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F2D0CB629319FE0005FDD2F /* Dirhelper.swift */; }; 2F2D0CB92931B341005FDD2F /* ArgsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F2D0CB82931B341005FDD2F /* ArgsManager.swift */; }; @@ -53,18 +44,8 @@ /* Begin PBXFileReference section */ 2F0235732A531F8F00A835C2 /* linux.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = linux.app; sourceTree = BUILT_PRODUCTS_DIR; }; - 2F0235752A531F8F00A835C2 /* linuxApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = linuxApp.swift; sourceTree = ""; }; - 2F0235772A531F8F00A835C2 /* Persistence.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Persistence.swift; sourceTree = ""; }; - 2F02357A2A531F8F00A835C2 /* linux.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = linux.xcdatamodel; sourceTree = ""; }; - 2F02357C2A531F8F00A835C2 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; - 2F02357E2A531F9000A835C2 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; - 2F0235802A531F9000A835C2 /* linux.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = linux.entitlements; sourceTree = ""; }; - 2F0235822A531F9000A835C2 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 2F0235882A531F9000A835C2 /* linuxTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = linuxTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 2F02358C2A531F9000A835C2 /* linuxTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = linuxTests.swift; sourceTree = ""; }; 2F0235922A531F9000A835C2 /* linuxUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = linuxUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 2F0235962A531F9000A835C2 /* linuxUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = linuxUITests.swift; sourceTree = ""; }; - 2F0235982A531F9000A835C2 /* linuxUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = linuxUITestsLaunchTests.swift; sourceTree = ""; }; 2F030676291B0A7E00F3C62C /* kubec-cmd */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "kubec-cmd"; sourceTree = BUILT_PRODUCTS_DIR; }; 2F030679291B0A7E00F3C62C /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; 2F2D0CB629319FE0005FDD2F /* Dirhelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Dirhelper.swift; path = "kubec-cmd/Dirhelper.swift"; sourceTree = ""; }; @@ -104,53 +85,11 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 2F0235742A531F8F00A835C2 /* linux */ = { - isa = PBXGroup; - children = ( - 2F0235752A531F8F00A835C2 /* linuxApp.swift */, - 2F0235772A531F8F00A835C2 /* Persistence.swift */, - 2F02357C2A531F8F00A835C2 /* ContentView.swift */, - 2F02357E2A531F9000A835C2 /* Assets.xcassets */, - 2F0235802A531F9000A835C2 /* linux.entitlements */, - 2F0235792A531F8F00A835C2 /* linux.xcdatamodeld */, - 2F0235812A531F9000A835C2 /* Preview Content */, - ); - path = linux; - sourceTree = ""; - }; - 2F0235812A531F9000A835C2 /* Preview Content */ = { - isa = PBXGroup; - children = ( - 2F0235822A531F9000A835C2 /* Preview Assets.xcassets */, - ); - path = "Preview Content"; - sourceTree = ""; - }; - 2F02358B2A531F9000A835C2 /* linuxTests */ = { - isa = PBXGroup; - children = ( - 2F02358C2A531F9000A835C2 /* linuxTests.swift */, - ); - path = linuxTests; - sourceTree = ""; - }; - 2F0235952A531F9000A835C2 /* linuxUITests */ = { - isa = PBXGroup; - children = ( - 2F0235962A531F9000A835C2 /* linuxUITests.swift */, - 2F0235982A531F9000A835C2 /* linuxUITestsLaunchTests.swift */, - ); - path = linuxUITests; - sourceTree = ""; - }; 2F03066D291B0A7E00F3C62C = { isa = PBXGroup; children = ( 2F2D0CB629319FE0005FDD2F /* Dirhelper.swift */, 2F030678291B0A7E00F3C62C /* kubec-cmd */, - 2F0235742A531F8F00A835C2 /* linux */, - 2F02358B2A531F9000A835C2 /* linuxTests */, - 2F0235952A531F9000A835C2 /* linuxUITests */, 2F030677291B0A7E00F3C62C /* Products */, ); sourceTree = ""; @@ -301,8 +240,6 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 2F0235832A531F9000A835C2 /* Preview Assets.xcassets in Resources */, - 2F02357F2A531F9000A835C2 /* Assets.xcassets in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -327,10 +264,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 2F0235762A531F8F00A835C2 /* linuxApp.swift in Sources */, - 2F0235782A531F8F00A835C2 /* Persistence.swift in Sources */, - 2F02357D2A531F8F00A835C2 /* ContentView.swift in Sources */, - 2F02357B2A531F8F00A835C2 /* linux.xcdatamodeld in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -338,7 +271,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 2F02358D2A531F9000A835C2 /* linuxTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -346,8 +278,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 2F0235972A531F9000A835C2 /* linuxUITests.swift in Sources */, - 2F0235992A531F9000A835C2 /* linuxUITestsLaunchTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -457,7 +387,6 @@ 2F02359E2A531F9000A835C2 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; BUNDLE_LOADER = "$(TEST_HOST)"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; @@ -480,7 +409,6 @@ 2F02359F2A531F9000A835C2 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; BUNDLE_LOADER = "$(TEST_HOST)"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; @@ -504,7 +432,6 @@ isa = XCBuildConfiguration; buildSettings = { ALLOW_TARGET_PLATFORM_SPECIALIZATION = YES; - ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_TEAM = 3HC7295HS9; @@ -528,7 +455,6 @@ isa = XCBuildConfiguration; buildSettings = { ALLOW_TARGET_PLATFORM_SPECIALIZATION = YES; - ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_TEAM = 3HC7295HS9; @@ -734,19 +660,6 @@ defaultConfigurationName = Release; }; /* End XCConfigurationList section */ - -/* Begin XCVersionGroup section */ - 2F0235792A531F8F00A835C2 /* linux.xcdatamodeld */ = { - isa = XCVersionGroup; - children = ( - 2F02357A2A531F8F00A835C2 /* linux.xcdatamodel */, - ); - currentVersion = 2F02357A2A531F8F00A835C2 /* linux.xcdatamodel */; - path = linux.xcdatamodeld; - sourceTree = ""; - versionGroupType = wrapper.xcdatamodel; - }; -/* End XCVersionGroup section */ }; rootObject = 2F03066E291B0A7E00F3C62C /* Project object */; } diff --git a/kubec-cmd.xcodeproj/xcshareddata/xcschemes/kubec-cmd --list.xcscheme b/kubec-cmd.xcodeproj/xcshareddata/xcschemes/kubec-cmd --list.xcscheme new file mode 100644 index 0000000..af49198 --- /dev/null +++ b/kubec-cmd.xcodeproj/xcshareddata/xcschemes/kubec-cmd --list.xcscheme @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/kubec-cmd.xcodeproj/xcuserdata/eddywister.xcuserdatad/xcschemes/kubec-cmd -t.xcscheme b/kubec-cmd.xcodeproj/xcuserdata/eddywister.xcuserdatad/xcschemes/kubec-cmd -t.xcscheme new file mode 100644 index 0000000..133572e --- /dev/null +++ b/kubec-cmd.xcodeproj/xcuserdata/eddywister.xcuserdatad/xcschemes/kubec-cmd -t.xcscheme @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/kubec-cmd.xcodeproj/xcuserdata/eddywister.xcuserdatad/xcschemes/xcschememanagement.plist b/kubec-cmd.xcodeproj/xcuserdata/eddywister.xcuserdatad/xcschemes/xcschememanagement.plist index 7d4e6cb..e80841a 100644 --- a/kubec-cmd.xcodeproj/xcuserdata/eddywister.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/kubec-cmd.xcodeproj/xcuserdata/eddywister.xcuserdatad/xcschemes/xcschememanagement.plist @@ -4,15 +4,22 @@ SchemeUserState - kubec-cmd.xcscheme_^#shared#^_ + kubec-cmd --list.xcscheme_^#shared#^_ orderHint - 0 + 1 - linux.xcscheme_^#shared#^_ + kubec-cmd -t.xcscheme orderHint - 1 + 2 + + kubec-cmd.xcscheme_^#shared#^_ + + isShown + + orderHint + 0 unix.xcscheme_^#shared#^_ @@ -22,14 +29,21 @@ SuppressBuildableAutocreation - 2F030675291B0A7E00F3C62C + 2F0235722A531F8F00A835C2 + + primary + + + 2F0235872A531F9000A835C2 + + primary + + + 2F0235912A531F9000A835C2 primary - - SuppressBuildableAutocreation - 2F030675291B0A7E00F3C62C primary diff --git a/kubec-cmd/ArgsManager.swift b/kubec-cmd/ArgsManager.swift index 5f23fdc..542cb5e 100644 --- a/kubec-cmd/ArgsManager.swift +++ b/kubec-cmd/ArgsManager.swift @@ -37,5 +37,5 @@ func ArgsController() -> Args { PrintInstructions() } - return target + return args } diff --git a/kubec-cmd/FilesManager.swift b/kubec-cmd/FilesManager.swift index b86e446..b35237a 100644 --- a/kubec-cmd/FilesManager.swift +++ b/kubec-cmd/FilesManager.swift @@ -113,7 +113,6 @@ func listfilesinpath () -> [String] for file in enumerator { if let file = file as? String { if file.contains(configsuffix) { -// if !file.contains("bk") && !file.contains(".back") && !file.contains(".0") && !file.contains(".1") && !file.contains(".2") && !file.contains(".3") { if !file.contains("bk") && !file.contains(".back") && file.contains("config_") { ConfigFound.append(file) } diff --git a/linux/Assets.xcassets/AccentColor.colorset/Contents.json b/linux/Assets.xcassets/AccentColor.colorset/Contents.json deleted file mode 100644 index eb87897..0000000 --- a/linux/Assets.xcassets/AccentColor.colorset/Contents.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "colors" : [ - { - "idiom" : "universal" - } - ], - "info" : { - "author" : "xcode", - "version" : 1 - } -} diff --git a/linux/Assets.xcassets/AppIcon.appiconset/Contents.json b/linux/Assets.xcassets/AppIcon.appiconset/Contents.json deleted file mode 100644 index 532cd72..0000000 --- a/linux/Assets.xcassets/AppIcon.appiconset/Contents.json +++ /dev/null @@ -1,63 +0,0 @@ -{ - "images" : [ - { - "idiom" : "universal", - "platform" : "ios", - "size" : "1024x1024" - }, - { - "idiom" : "mac", - "scale" : "1x", - "size" : "16x16" - }, - { - "idiom" : "mac", - "scale" : "2x", - "size" : "16x16" - }, - { - "idiom" : "mac", - "scale" : "1x", - "size" : "32x32" - }, - { - "idiom" : "mac", - "scale" : "2x", - "size" : "32x32" - }, - { - "idiom" : "mac", - "scale" : "1x", - "size" : "128x128" - }, - { - "idiom" : "mac", - "scale" : "2x", - "size" : "128x128" - }, - { - "idiom" : "mac", - "scale" : "1x", - "size" : "256x256" - }, - { - "idiom" : "mac", - "scale" : "2x", - "size" : "256x256" - }, - { - "idiom" : "mac", - "scale" : "1x", - "size" : "512x512" - }, - { - "idiom" : "mac", - "scale" : "2x", - "size" : "512x512" - } - ], - "info" : { - "author" : "xcode", - "version" : 1 - } -} diff --git a/linux/Assets.xcassets/Contents.json b/linux/Assets.xcassets/Contents.json deleted file mode 100644 index 73c0059..0000000 --- a/linux/Assets.xcassets/Contents.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "info" : { - "author" : "xcode", - "version" : 1 - } -} diff --git a/linux/ContentView.swift b/linux/ContentView.swift deleted file mode 100644 index 92efbf4..0000000 --- a/linux/ContentView.swift +++ /dev/null @@ -1,90 +0,0 @@ -// -// ContentView.swift -// linux -// -// Created by Eddy Wister on 03/07/23. -// - -import SwiftUI -import CoreData - -struct ContentView: View { - @Environment(\.managedObjectContext) private var viewContext - - @FetchRequest( - sortDescriptors: [NSSortDescriptor(keyPath: \Item.timestamp, ascending: true)], - animation: .default) - private var items: FetchedResults - - var body: some View { - NavigationView { - List { - ForEach(items) { item in - NavigationLink { - Text("Item at \(item.timestamp!, formatter: itemFormatter)") - } label: { - Text(item.timestamp!, formatter: itemFormatter) - } - } - .onDelete(perform: deleteItems) - } - .toolbar { -#if os(iOS) - ToolbarItem(placement: .navigationBarTrailing) { - EditButton() - } -#endif - ToolbarItem { - Button(action: addItem) { - Label("Add Item", systemImage: "plus") - } - } - } - Text("Select an item") - } - } - - private func addItem() { - withAnimation { - let newItem = Item(context: viewContext) - newItem.timestamp = Date() - - do { - try viewContext.save() - } catch { - // Replace this implementation with code to handle the error appropriately. - // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. - let nsError = error as NSError - fatalError("Unresolved error \(nsError), \(nsError.userInfo)") - } - } - } - - private func deleteItems(offsets: IndexSet) { - withAnimation { - offsets.map { items[$0] }.forEach(viewContext.delete) - - do { - try viewContext.save() - } catch { - // Replace this implementation with code to handle the error appropriately. - // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. - let nsError = error as NSError - fatalError("Unresolved error \(nsError), \(nsError.userInfo)") - } - } - } -} - -private let itemFormatter: DateFormatter = { - let formatter = DateFormatter() - formatter.dateStyle = .short - formatter.timeStyle = .medium - return formatter -}() - -struct ContentView_Previews: PreviewProvider { - static var previews: some View { - ContentView().environment(\.managedObjectContext, PersistenceController.preview.container.viewContext) - } -} diff --git a/linux/Persistence.swift b/linux/Persistence.swift deleted file mode 100644 index 25529c9..0000000 --- a/linux/Persistence.swift +++ /dev/null @@ -1,56 +0,0 @@ -// -// Persistence.swift -// linux -// -// Created by Eddy Wister on 03/07/23. -// - -import CoreData - -struct PersistenceController { - static let shared = PersistenceController() - - static var preview: PersistenceController = { - let result = PersistenceController(inMemory: true) - let viewContext = result.container.viewContext - for _ in 0..<10 { - let newItem = Item(context: viewContext) - newItem.timestamp = Date() - } - do { - try viewContext.save() - } catch { - // Replace this implementation with code to handle the error appropriately. - // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. - let nsError = error as NSError - fatalError("Unresolved error \(nsError), \(nsError.userInfo)") - } - return result - }() - - let container: NSPersistentContainer - - init(inMemory: Bool = false) { - container = NSPersistentContainer(name: "linux") - if inMemory { - container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: "/dev/null") - } - container.loadPersistentStores(completionHandler: { (storeDescription, error) in - if let error = error as NSError? { - // Replace this implementation with code to handle the error appropriately. - // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. - - /* - Typical reasons for an error here include: - * The parent directory does not exist, cannot be created, or disallows writing. - * The persistent store is not accessible, due to permissions or data protection when the device is locked. - * The device is out of space. - * The store could not be migrated to the current model version. - Check the error message to determine what the actual problem was. - */ - fatalError("Unresolved error \(error), \(error.userInfo)") - } - }) - container.viewContext.automaticallyMergesChangesFromParent = true - } -} diff --git a/linux/Preview Content/Preview Assets.xcassets/Contents.json b/linux/Preview Content/Preview Assets.xcassets/Contents.json deleted file mode 100644 index 73c0059..0000000 --- a/linux/Preview Content/Preview Assets.xcassets/Contents.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "info" : { - "author" : "xcode", - "version" : 1 - } -} diff --git a/linux/linux.entitlements b/linux/linux.entitlements deleted file mode 100644 index f2ef3ae..0000000 --- a/linux/linux.entitlements +++ /dev/null @@ -1,10 +0,0 @@ - - - - - com.apple.security.app-sandbox - - com.apple.security.files.user-selected.read-only - - - diff --git a/linux/linux.xcdatamodeld/.xccurrentversion b/linux/linux.xcdatamodeld/.xccurrentversion index 997809e..0c67376 100644 --- a/linux/linux.xcdatamodeld/.xccurrentversion +++ b/linux/linux.xcdatamodeld/.xccurrentversion @@ -1,8 +1,5 @@ - - _XCCurrentVersionName - linux.xcdatamodel - + diff --git a/linux/linuxApp.swift b/linux/linuxApp.swift deleted file mode 100644 index 3870426..0000000 --- a/linux/linuxApp.swift +++ /dev/null @@ -1,20 +0,0 @@ -// -// linuxApp.swift -// linux -// -// Created by Eddy Wister on 03/07/23. -// - -import SwiftUI - -@main -struct linuxApp: App { - let persistenceController = PersistenceController.shared - - var body: some Scene { - WindowGroup { - ContentView() - .environment(\.managedObjectContext, persistenceController.container.viewContext) - } - } -} diff --git a/linuxTests/linuxTests.swift b/linuxTests/linuxTests.swift deleted file mode 100644 index 5682800..0000000 --- a/linuxTests/linuxTests.swift +++ /dev/null @@ -1,35 +0,0 @@ -// -// linuxTests.swift -// linuxTests -// -// Created by Eddy Wister on 03/07/23. -// - -import XCTest - -final class linuxTests: XCTestCase { - - override func setUpWithError() throws { - // Put setup code here. This method is called before the invocation of each test method in the class. - } - - override func tearDownWithError() throws { - // Put teardown code here. This method is called after the invocation of each test method in the class. - } - - func testExample() throws { - // This is an example of a functional test case. - // Use XCTAssert and related functions to verify your tests produce the correct results. - // Any test you write for XCTest can be annotated as throws and async. - // Mark your test throws to produce an unexpected failure when your test encounters an uncaught error. - // Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards. - } - - func testPerformanceExample() throws { - // This is an example of a performance test case. - measure { - // Put the code you want to measure the time of here. - } - } - -} diff --git a/linuxUITests/linuxUITests.swift b/linuxUITests/linuxUITests.swift deleted file mode 100644 index c8908f5..0000000 --- a/linuxUITests/linuxUITests.swift +++ /dev/null @@ -1,41 +0,0 @@ -// -// linuxUITests.swift -// linuxUITests -// -// Created by Eddy Wister on 03/07/23. -// - -import XCTest - -final class linuxUITests: XCTestCase { - - override func setUpWithError() throws { - // Put setup code here. This method is called before the invocation of each test method in the class. - - // In UI tests it is usually best to stop immediately when a failure occurs. - continueAfterFailure = false - - // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. - } - - override func tearDownWithError() throws { - // Put teardown code here. This method is called after the invocation of each test method in the class. - } - - func testExample() throws { - // UI tests must launch the application that they test. - let app = XCUIApplication() - app.launch() - - // Use XCTAssert and related functions to verify your tests produce the correct results. - } - - func testLaunchPerformance() throws { - if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 7.0, *) { - // This measures how long it takes to launch your application. - measure(metrics: [XCTApplicationLaunchMetric()]) { - XCUIApplication().launch() - } - } - } -} diff --git a/linuxUITests/linuxUITestsLaunchTests.swift b/linuxUITests/linuxUITestsLaunchTests.swift deleted file mode 100644 index 2b31e7a..0000000 --- a/linuxUITests/linuxUITestsLaunchTests.swift +++ /dev/null @@ -1,32 +0,0 @@ -// -// linuxUITestsLaunchTests.swift -// linuxUITests -// -// Created by Eddy Wister on 03/07/23. -// - -import XCTest - -final class linuxUITestsLaunchTests: XCTestCase { - - override class var runsForEachTargetApplicationUIConfiguration: Bool { - true - } - - override func setUpWithError() throws { - continueAfterFailure = false - } - - func testLaunch() throws { - let app = XCUIApplication() - app.launch() - - // Insert steps here to perform after app launch but before taking a screenshot, - // such as logging into a test account or navigating somewhere in the app - - let attachment = XCTAttachment(screenshot: app.screenshot()) - attachment.name = "Launch Screen" - attachment.lifetime = .keepAlways - add(attachment) - } -} From 7f8d5a28ced9effb1acea2e71f8e287e5fc85dd6 Mon Sep 17 00:00:00 2001 From: Wister Date: Fri, 28 Jul 2023 14:47:29 -0600 Subject: [PATCH 5/8] First refactor --- KubeConfigList.swift | 26 +++++++++++++++++++ kubec-cmd.xcodeproj/project.pbxproj | 4 +++ .../xcdebugger/Breakpoints_v2.xcbkptlist | 25 ++++++++++++++---- kubec-cmd/FilesManager.swift | 18 ------------- 4 files changed, 50 insertions(+), 23 deletions(-) create mode 100644 KubeConfigList.swift diff --git a/KubeConfigList.swift b/KubeConfigList.swift new file mode 100644 index 0000000..98da173 --- /dev/null +++ b/KubeConfigList.swift @@ -0,0 +1,26 @@ +// +// KubeConfigList.swift +// kubec-cmd +// +// Created by Eddy Wister on 28/07/23. +// + +import Foundation + +func listfilesinpath () -> [String] +{ + let home = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(".kube").path(); + let fileManager = FileManager.default + let enumerator:FileManager.DirectoryEnumerator = fileManager.enumerator(atPath: home)! + var ConfigFound = [String]() + for file in enumerator { + if let file = file as? String { + if file.contains(configsuffix) { + if !file.contains("bk") && !file.contains(".back") && file.contains("config_") { + ConfigFound.append(file) + } + } + } + } + return ConfigFound +} diff --git a/kubec-cmd.xcodeproj/project.pbxproj b/kubec-cmd.xcodeproj/project.pbxproj index 0401887..58b36ee 100644 --- a/kubec-cmd.xcodeproj/project.pbxproj +++ b/kubec-cmd.xcodeproj/project.pbxproj @@ -11,6 +11,7 @@ 2F2D0CB729319FE0005FDD2F /* Dirhelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F2D0CB629319FE0005FDD2F /* Dirhelper.swift */; }; 2F2D0CB92931B341005FDD2F /* ArgsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F2D0CB82931B341005FDD2F /* ArgsManager.swift */; }; 2F2D0CBB2931C2D7005FDD2F /* FilesManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F2D0CBA2931C2D7005FDD2F /* FilesManager.swift */; }; + 2FA295C62A7460480002F584 /* KubeConfigList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FA295C52A7460480002F584 /* KubeConfigList.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -51,6 +52,7 @@ 2F2D0CB629319FE0005FDD2F /* Dirhelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Dirhelper.swift; path = "kubec-cmd/Dirhelper.swift"; sourceTree = ""; }; 2F2D0CB82931B341005FDD2F /* ArgsManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArgsManager.swift; sourceTree = ""; }; 2F2D0CBA2931C2D7005FDD2F /* FilesManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilesManager.swift; sourceTree = ""; }; + 2FA295C52A7460480002F584 /* KubeConfigList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KubeConfigList.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -88,6 +90,7 @@ 2F03066D291B0A7E00F3C62C = { isa = PBXGroup; children = ( + 2FA295C52A7460480002F584 /* KubeConfigList.swift */, 2F2D0CB629319FE0005FDD2F /* Dirhelper.swift */, 2F030678291B0A7E00F3C62C /* kubec-cmd */, 2F030677291B0A7E00F3C62C /* Products */, @@ -287,6 +290,7 @@ files = ( 2F2D0CB92931B341005FDD2F /* ArgsManager.swift in Sources */, 2F03067A291B0A7E00F3C62C /* main.swift in Sources */, + 2FA295C62A7460480002F584 /* KubeConfigList.swift in Sources */, 2F2D0CB729319FE0005FDD2F /* Dirhelper.swift in Sources */, 2F2D0CBB2931C2D7005FDD2F /* FilesManager.swift in Sources */, ); diff --git a/kubec-cmd.xcodeproj/xcuserdata/eddywister.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/kubec-cmd.xcodeproj/xcuserdata/eddywister.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 40009cb..7987f14 100644 --- a/kubec-cmd.xcodeproj/xcuserdata/eddywister.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/kubec-cmd.xcodeproj/xcuserdata/eddywister.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -80,7 +80,7 @@ endingColumnNumber = "9223372036854775807" startingLineNumber = "19" endingLineNumber = "19" - landmarkName = "SearchFiles(target:)" + landmarkName = "SearchFiles(target:context:)" landmarkType = "9"> @@ -88,7 +88,7 @@ BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint"> + + @@ -174,8 +189,8 @@ endingColumnNumber = "9223372036854775807" startingLineNumber = "105" endingLineNumber = "105" - landmarkName = "listfilesinpath()" - landmarkType = "9"> + landmarkName = "unknown" + landmarkType = "0"> [String] -{ - let home = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(".kube").path(); - let fileManager = FileManager.default - let enumerator:FileManager.DirectoryEnumerator = fileManager.enumerator(atPath: home)! - var ConfigFound = [String]() - for file in enumerator { - if let file = file as? String { - if file.contains(configsuffix) { - if !file.contains("bk") && !file.contains(".back") && file.contains("config_") { - ConfigFound.append(file) - } - } - } - } - return ConfigFound -} From 21d796272127d1a5bfb326c36fda7107abd940db Mon Sep 17 00:00:00 2001 From: Wister Date: Fri, 28 Jul 2023 15:47:04 -0600 Subject: [PATCH 6/8] Refactor pt 2 --- KubeConfigList.swift | 5 ++--- kubec-cmd/ArgsManager.swift | 8 ++++++-- kubec-cmd/FilesManager.swift | 27 +++++++++++++++++++-------- kubec-cmd/main.swift | 32 ++++++-------------------------- 4 files changed, 33 insertions(+), 39 deletions(-) diff --git a/KubeConfigList.swift b/KubeConfigList.swift index 98da173..bb9e760 100644 --- a/KubeConfigList.swift +++ b/KubeConfigList.swift @@ -9,14 +9,13 @@ import Foundation func listfilesinpath () -> [String] { - let home = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(".kube").path(); let fileManager = FileManager.default - let enumerator:FileManager.DirectoryEnumerator = fileManager.enumerator(atPath: home)! + let enumerator:FileManager.DirectoryEnumerator = fileManager.enumerator(atPath: kubeconfig.path.description)! var ConfigFound = [String]() for file in enumerator { if let file = file as? String { if file.contains(configsuffix) { - if !file.contains("bk") && !file.contains(".back") && file.contains("config_") { + if !file.contains("bk") && !file.contains(".back") && file.contains(configsuffix) { ConfigFound.append(file) } } diff --git a/kubec-cmd/ArgsManager.swift b/kubec-cmd/ArgsManager.swift index 542cb5e..5ee0644 100644 --- a/kubec-cmd/ArgsManager.swift +++ b/kubec-cmd/ArgsManager.swift @@ -21,12 +21,12 @@ func ArgsController() -> Args { print("Argument 1 ↪︎ ", arguments[targetIndex]) print("Argument 2 ↪︎ ", arguments[targetIndex + 1]) print("Target found ➥", targetFile) + SearchFiles(target: args.target, context: args.context) } - //new arg --list using this method listfilesinpath() else if arguments.contains("--list") { let files = listfilesinpath() - print("List of files in path: ",kubeconfig) + print("List of files in path: ",kubeconfig.path.description) for file in files { print(file) } @@ -39,3 +39,7 @@ func ArgsController() -> Args { return args } + + + + diff --git a/kubec-cmd/FilesManager.swift b/kubec-cmd/FilesManager.swift index d8d6a4b..024ca8d 100644 --- a/kubec-cmd/FilesManager.swift +++ b/kubec-cmd/FilesManager.swift @@ -6,15 +6,12 @@ import Foundation -let dir = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(".kube").appendingPathComponent("bk") -var _target = "" -var _context = "" - func SearchFiles(target: String, context: String) { _target = target _context = context CreateBackUpDirectory() Makebackup() + getconfig() Clean() SwitcherConfig() @@ -23,12 +20,26 @@ func SearchFiles(target: String, context: String) { func CreateBackUpDirectory(){ //create directory do { - try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true, attributes: nil) + try FileManager.default.createDirectory(at: dirbk, withIntermediateDirectories: true, attributes: nil) } catch let error as NSError { print(error.localizedDescription); } } - +func getconfig () +{ + // list of string + //Select confifiles + for file in enumerator { + if let file = file as? String { + if file.contains(configsuffix) { + if !file.contains("bk") && !file.contains(".back") + { + ConfigFound.append(file) + } + } + } + } +} func Makebackup() { //date forma date + time let date = Date() @@ -39,7 +50,7 @@ func Makebackup() { //copy files .kube to .kube/bk and append _date + time for file in ConfigFound { let source = kubeconfig.appendingPathComponent(file) - let destination = dir.appendingPathComponent(file).appendingPathExtension(result) + let destination = dirbk.appendingPathComponent(file).appendingPathExtension(result) do { try FileManager.default.copyItem(at: source, to: destination) } catch let error as NSError { @@ -77,7 +88,7 @@ func SwitcherConfig() { } if existTarget { - let targetfile = "config_"+_target + let targetfile = configsuffix+_target let source = kubeconfig.appendingPathComponent(targetfile) let destination = kubeconfigDir do { diff --git a/kubec-cmd/main.swift b/kubec-cmd/main.swift index 5b13649..2b7ce9d 100644 --- a/kubec-cmd/main.swift +++ b/kubec-cmd/main.swift @@ -9,35 +9,15 @@ import Foundation let configsuffix = "config_" let kubeconfigDir = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(".kube").appendingPathComponent("config") let kubeconfig = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(".kube") - +let dirbk = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(".kube").appendingPathComponent("bk") +var _target = "" +var _context = "" +var ConfigFound = [String]() +let fileManager = FileManager.default +let enumerator:FileManager.DirectoryEnumerator = fileManager.enumerator(atPath: kubeconfig.path())! PrintInstructions() // Modified to handle both target and context arguments let args = ArgsController() -let target = args.target -let context = args.context - -if target.isEmpty { - print("Fail") -} -//get files in path -let fileManager = FileManager.default -let enumerator:FileManager.DirectoryEnumerator = fileManager.enumerator(atPath: kubeconfig.path())! - -// list of string -var ConfigFound = [String]() -//Select confifiles -for file in enumerator { - if let file = file as? String { - if file.contains(configsuffix) { - if !file.contains("bk") && !file.contains(".back") - { - ConfigFound.append(file) - } - } - } -} -// Modified to handle context argument -SearchFiles(target: target, context: context) From 3e6f7ff6b51d049ee707a9ae9983ffe8ec9e9c46 Mon Sep 17 00:00:00 2001 From: Wister Date: Fri, 28 Jul 2023 15:49:57 -0600 Subject: [PATCH 7/8] Refactor --- kubec-cmd/FilesManager.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kubec-cmd/FilesManager.swift b/kubec-cmd/FilesManager.swift index 024ca8d..dafef26 100644 --- a/kubec-cmd/FilesManager.swift +++ b/kubec-cmd/FilesManager.swift @@ -53,7 +53,7 @@ func Makebackup() { let destination = dirbk.appendingPathComponent(file).appendingPathExtension(result) do { try FileManager.default.copyItem(at: source, to: destination) - } catch let error as NSError { + } catch _ as NSError { print("Error on Create backup ⚠️") } } @@ -71,7 +71,7 @@ func Clean () { if exist{ do { try FileManager.default.removeItem(at: kubeconfigDir) - } catch let error as NSError { + } catch _ as NSError { print("Error on Create backup ⚠️") } } From ade707e2ae0ebc61e77604cbd9fb5cf21aa67e70 Mon Sep 17 00:00:00 2001 From: Wister Date: Fri, 28 Jul 2023 15:53:16 -0600 Subject: [PATCH 8/8] Minor fixes --- kubec-cmd/ArgsManager.swift | 5 +++-- kubec-cmd/Dirhelper.swift | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/kubec-cmd/ArgsManager.swift b/kubec-cmd/ArgsManager.swift index 5ee0644..ef13721 100644 --- a/kubec-cmd/ArgsManager.swift +++ b/kubec-cmd/ArgsManager.swift @@ -18,8 +18,9 @@ func ArgsController() -> Args { if let targetIndex = arguments.firstIndex(of: "-t"), arguments.count > targetIndex + 1 { let targetFile = arguments[targetIndex + 1] args.target = targetFile - print("Argument 1 ↪︎ ", arguments[targetIndex]) - print("Argument 2 ↪︎ ", arguments[targetIndex + 1]) + //only for debug +// print("Argument 1 ↪︎ ", arguments[targetIndex]) +// print("Argument 2 ↪︎ ", arguments[targetIndex + 1]) print("Target found ➥", targetFile) SearchFiles(target: args.target, context: args.context) } diff --git a/kubec-cmd/Dirhelper.swift b/kubec-cmd/Dirhelper.swift index 580a373..3bbf23e 100644 --- a/kubec-cmd/Dirhelper.swift +++ b/kubec-cmd/Dirhelper.swift @@ -16,5 +16,7 @@ func PrintInstructions() { print("🛠️---------------------------------------------------------------------------------------------------🛠️") print("Using a specific context 📝: kubec-cmd -t 'subfix' -c 'context'") print("🛠️---------------------------------------------------------------------------------------------------🛠️") + print("List config files 📝: kubec-cmd --list") + print("🛠️---------------------------------------------------------------------------------------------------🛠️") }