diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml index c4be241..d1890af 100644 --- a/.github/workflows/swift.yml +++ b/.github/workflows/swift.yml @@ -2,9 +2,9 @@ name: CI on: push: - branches: [ devel ] + branches: [ master ] pull_request: - branches: [ devel ] + branches: [ master ] jobs: build: diff --git a/CHANGELOG.md b/CHANGELOG.md index 0277256..119482e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,3 +15,13 @@ - Changes `--tags` to `--append-tags` for push command. - Allows content to pulled with specific tags in pull command. - Formats found strings on push command correctly. + +## Transifex Command Line Tool 1.0.0 + +*July 29, 2021* + +- Updates Transifex Swift library to 1.0.0. +- Adds initial value to `withTagsOnly` argument so that is not required. +- Displays custom message when max retries have been exhausted during the push operation. +- Uses animated cursor from CLISpinner library while waiting for a response from CDS when +verbose flag is not provided. diff --git a/Package.resolved b/Package.resolved index 812820d..5769c8b 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,6 +1,24 @@ { "object": { "pins": [ + { + "package": "CLISpinner", + "repositoryURL": "https://github.com/kiliankoe/CLISpinner", + "state": { + "branch": null, + "revision": "0572232b92ddfd80cbab4ced6973d1c210022968", + "version": "0.4.0" + } + }, + { + "package": "Rainbow", + "repositoryURL": "https://github.com/onevcat/Rainbow", + "state": { + "branch": null, + "revision": "626c3d4b6b55354b4af3aa309f998fae9b31a3d9", + "version": "3.2.0" + } + }, { "package": "swift-argument-parser", "repositoryURL": "https://github.com/apple/swift-argument-parser", @@ -15,8 +33,8 @@ "repositoryURL": "https://github.com/transifex/transifex-swift", "state": { "branch": null, - "revision": "47d47d4eee281da15721285b86f75539d4061fff", - "version": "0.5.0" + "revision": "1a79564a8c51ef748c9f4a27fb3e3e10d6dbe9d0", + "version": "1.0.0" } } ] diff --git a/Package.swift b/Package.swift index 017ce83..b01a597 100644 --- a/Package.swift +++ b/Package.swift @@ -15,9 +15,11 @@ let package = Package( dependencies: [ .package(name: "transifex", url: "https://github.com/transifex/transifex-swift", - from: "0.5.0"), + from: "1.0.0"), .package(url: "https://github.com/apple/swift-argument-parser", from: "0.3.0"), + .package(url: "https://github.com/kiliankoe/CLISpinner", + from: "0.4.0") ], targets: [ .target( @@ -27,6 +29,7 @@ let package = Package( package: "transifex"), .product(name: "ArgumentParser", package: "swift-argument-parser"), + "CLISpinner" ] ), .target( diff --git a/Sources/TXCli/main.swift b/Sources/TXCli/main.swift index 87e6d50..70601ba 100644 --- a/Sources/TXCli/main.swift +++ b/Sources/TXCli/main.swift @@ -10,6 +10,7 @@ import Transifex import TXCliLib import ArgumentParser import Foundation +import CLISpinner /// All possible error codes that might trigger a failure during the execution of a TXCli command. enum CommandError : Error { @@ -41,7 +42,7 @@ that can be bundled with the iOS application. The tool can be also used to force CDS cache invalidation so that the next pull command will fetch fresh translations from CDS. """, - version: "0.1.0", + version: "1.0.0", subcommands: [Push.self, Pull.self, Invalidate.self]) } @@ -209,23 +210,61 @@ the CDS server. [high]Pushing[end] [num]\(translations.count)[end] [high]source strings to CDS ([end][prompt]Purge: \(purge ? "Yes" : "No")[end][high])...[end] """) + let spinner = Spinner(pattern: .dots, text: "Pushing") + if !options.verbose { + spinner.start() + } + // Block until the push logic completes using a semaphore. let semaphore = DispatchSemaphore(value: 0) var pushResult = false + var pushErrors: [Error] = [] + TXNative.pushTranslations(translations, - purge: purge) { (result) in + purge: purge) { (result, errors) in pushResult = result + pushErrors = errors semaphore.signal() } semaphore.wait() + if !options.verbose { + spinner.stopAndClear() + } + if !pushResult { - logHandler.error("Error while pushing source strings to CDS") - throw CommandError.cdsPushFailure + if containsMaxRetriesReachedError(pushErrors) { + logHandler.info("[prompt]Strings are queued for processing[end]") + } + else { + logHandler.error("Error while pushing source strings to CDS") + throw CommandError.cdsPushFailure + } + } + else { + logHandler.info(""" +[success]✓[end] [num]\(translations.count)[end][success] source strings pushed successfully[end] +""") + } + } + + /// Reports whether the passed array of errors contains a max retries reached error or not. + /// + /// - Parameter errors: Passed array of errors as returned by the pushTranslations() method + /// - Returns: true if the array contains a max retries reached error, false otherwise + func containsMaxRetriesReachedError(_ errors: [Error]) -> Bool { + guard errors.count > 0 else { + return false + } + + for error in errors { + if case TXCDSError.maxRetriesReached = error { + return true + } } - logHandler.info("[success]✓[end] [num]\(translations.count)[end][success] source strings pushed successfully[end]") + return false } } @@ -263,7 +302,7 @@ will try to create it (alongside any intermediate folders). @Option(name: .long, parsing: .upToNextOption, help: """ If set, only the strings that have all of the given tags will be downloaded. """) - private var withTagsOnly: [String] + private var withTagsOnly: [String] = [] func run() throws { let logHandler = CliLogHandler() @@ -288,6 +327,11 @@ If set, only the strings that have all of the given tags will be downloaded. logHandler.info("[high]Fetching translations from CDS...[end]") + let spinner = Spinner(pattern: .dots, text: "Fetching") + if !options.verbose { + spinner.start() + } + // Block until the pull logic completes using a semaphore. let semaphore = DispatchSemaphore(value: 0) var appTranslations: [String: TXLocaleStrings] = [:] @@ -301,6 +345,10 @@ If set, only the strings that have all of the given tags will be downloaded. semaphore.wait() + if !options.verbose { + spinner.stopAndClear() + } + guard appErrors.count == 0 else { logHandler.error("Errors while fetching translations from CDS: \(appErrors)") throw CommandError.cdsPullFailure diff --git a/Sources/TXCliLib/CliLogHandler.swift b/Sources/TXCliLib/CliLogHandler.swift index deb4f1f..5a16c37 100644 --- a/Sources/TXCliLib/CliLogHandler.swift +++ b/Sources/TXCliLib/CliLogHandler.swift @@ -44,6 +44,9 @@ public class CliLogHandler: TXLogHandler { /// Extension responsible for printing the debug description of a TXSourceString to the console with proper /// styling. extension TXSourceString { + /// Stylize the debug description of the TXSourceString for the CLI needs. + /// + /// We are aware of the 'method in category overrides method from class' warning(s) produced here. public override var debugDescription: String { var description = "\n"