Skip to content

Commit

Permalink
Implement dry run and style TXSourceString properly
Browse files Browse the repository at this point in the history
1. Updates `README` with clarification regarding the `verbose` argument
conflict when running the CLI tool using the `swift run` command.
2. Adds `dryRun` flag so that the CLI tool won't actually send anything
to CDS, which is useful for testing the command.
3. Removes the comment regarding ignoring the source locale when pulling
strings from the CDS.
4. Styles the `TXSourceString` instances when printed (via the
`debugDescription` property) accordingly.

3. Depends on transifex/transifex-swift#28
4. Depends on transifex/transifex-swift#29
  • Loading branch information
stelabouras committed Jun 23, 2021
1 parent af01445 commit 3cdbdce
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ The following calls can be either made from within the `TXCli` project directory
or after following the installation instructions above, from any folder of your computer by:
`txios-cli <cli command>`.

Bear in mind that due to naming collision, the `--verbose` flag won't be detected if the
`txios-cli` is executed via the `swift run` command, as the flag will be applied on the
`swift` executable instead. So to avoid collisions like this, it's recommended to execute
`txios-cli` directly after building it.

For simplicity the following examples will use the latter command.

#### Help
Expand Down
17 changes: 16 additions & 1 deletion Sources/TXCli/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ the CDS server.
""")
private var tags: [String] = []

@Flag(name: .long, help: "Do not push to CDS.")
private var dryRun: Bool = false

func run() throws {
let logHandler = CliLogHandler()
logHandler.verbose = options.verbose
Expand Down Expand Up @@ -183,6 +186,17 @@ the CDS server.

translations.append(translationUnit)
}

logHandler.info("""
[high]Found[end] [num]\(translations.count)[end] [high]source strings[end]
""")

guard dryRun == false else {
logHandler.warning("[warn]Dry run: no strings will be pushed to CDS")

logHandler.verbose("Translations: \(translations.debugDescription)")
return
}

logHandler.verbose("[high]Initializing TxNative...[end]")

Expand Down Expand Up @@ -234,7 +248,8 @@ or via the --token parameter.

@Option(name: .long, parsing: .upToNextOption, help: """
A list of the available locales that the application supports and will be
downloaded from CDS. The source locale, if added, is ignored.
downloaded from CDS. If both source and target locales are provided in the list,
they will also be requested from CDS.
""")
private var translatedLocales: [String]

Expand Down
30 changes: 30 additions & 0 deletions Sources/TXCliLib/CliLogHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,36 @@ public class CliLogHandler: TXLogHandler {
}
}

/// Extension responsible for printing the debug description of a TXSourceString to the console with proper
/// styling.
extension TXSourceString {
public override var debugDescription: String {
var description = "\n"

description += "[green]\"\(sourceString)\"[end]\n"

if let context = context {
description += "[high]context:[end] \(context.debugDescription)\n"
}

if let developerComment = developerComment {
description += "[high]comment:[end] \(developerComment)\n"
}

if characterLimit > 0 {
description += "[high]character limit:[end] \(characterLimit)\n"
}

if let tags = tags, tags.count > 0 {
description += "[high]tags:[end] \(tags.joined(separator: ", "))\n"
}

description += " [high]occurrences:[end] [file]\(occurrences.joined(separator: ", "))[end]\n"

return description
}
}

/// Convenience class for adding color to console output.
class CliSyntaxColor {
static let WHITE_BOLD = "\u{001B}[0;1m"
Expand Down

0 comments on commit 3cdbdce

Please sign in to comment.