From 5d7cb8c41cd4a05c70dbafcda9d0987f6398ff6d Mon Sep 17 00:00:00 2001 From: MarkG Date: Thu, 25 Jul 2024 14:41:22 +0700 Subject: [PATCH] [#560] Improve code --- .../iOSTemplateMaker/Helpers/Terminal.swift | 23 +++++++++---------- .../iOSTemplateMaker/SetUpCICDService.swift | 6 ++--- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/Helpers/Terminal.swift b/Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/Helpers/Terminal.swift index ba565658..4e0979c4 100644 --- a/Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/Helpers/Terminal.swift +++ b/Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/Helpers/Terminal.swift @@ -10,7 +10,6 @@ import ANSITerminal enum WriteStyle { - case section case success case error case warning @@ -18,10 +17,6 @@ enum WriteStyle { func write(_ text: String, style: WriteStyle) { switch style { - case .section: - writeln("-------------------".green) - writeln(text.green) - writeln("-------------------".green) case .success: writeln(text.green) case .error: @@ -105,23 +100,27 @@ private func getWroteLineCount(_ text: String) -> Int { private func unexpand(text: String) -> String { var result = "" var spaceCount = 0 + + func appendSpacesAndTabs() { + result.append(String(repeating: "\t", count: spaceCount / 8)) + result.append(String(repeating: " ", count: spaceCount % 8)) + spaceCount = 0 + } + for char in text { if char == " " { spaceCount += 1 } else { if spaceCount > 0 { - let tabs = String(repeating: "\t", count: spaceCount / 8) - let spaces = String(repeating: " ", count: spaceCount % 8) - result += tabs + spaces - spaceCount = 0 + appendSpacesAndTabs() } result += String(char) } } + if spaceCount > 0 { - let tabs = String(repeating: "\t", count: spaceCount / 8) - let spaces = String(repeating: " ", count: spaceCount % 8) - result += tabs + spaces + appendSpacesAndTabs() } + return result } diff --git a/Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/SetUpCICDService.swift b/Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/SetUpCICDService.swift index 9f212855..fd345320 100644 --- a/Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/SetUpCICDService.swift +++ b/Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/SetUpCICDService.swift @@ -29,7 +29,7 @@ struct SetUpCICDService { var title: String { switch self { case .github: - "Github" + "GitHub" case .bitrise: "Bitrise" case .codemagic: @@ -47,7 +47,7 @@ struct SetUpCICDService { init?(_ name: String) { let mappings: [String: Self] = [ "m": .macOSLatest, - "macos": .macOSLatest, + "macos-latest": .macOSLatest, "s": .selfHosted, "self-hosted": .selfHosted, "l": .later, @@ -65,7 +65,7 @@ struct SetUpCICDService { var title: String { switch self { case .macOSLatest: - "macos" + "macos-latest" case .selfHosted: "self-hosted" case .later: