-
-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathNormalizeOptions.swift
More file actions
41 lines (35 loc) · 1.51 KB
/
NormalizeOptions.swift
File metadata and controls
41 lines (35 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import BartyCrouchUtility
import Foundation
import Toml
public struct NormalizeOptions {
public let paths: [String]
public let subpathsToIgnore: [String]
public let sourceLocale: String
public let harmonizeWithSource: Bool
public let sortByKeys: Bool
public let separateWithEmptyLine: Bool
}
extension NormalizeOptions: TomlCodable {
static func make(toml: Toml) throws -> NormalizeOptions {
let update: String = "update"
let normalize: String = "normalize"
return NormalizeOptions(
paths: toml.filePaths(update, normalize, singularKey: "path", pluralKey: "paths"),
subpathsToIgnore: toml.array(update, normalize, "subpathsToIgnore") ?? Constants.defaultSubpathsToIgnore,
sourceLocale: toml.string(update, normalize, "sourceLocale") ?? "en",
harmonizeWithSource: toml.bool(update, normalize, "harmonizeWithSource") ?? true,
sortByKeys: toml.bool(update, normalize, "sortByKeys") ?? true,
separateWithEmptyLine: toml.bool(update, normalize, "separateWithEmptyLine") ?? true
)
}
func tomlContents() -> String {
var lines: [String] = ["[update.normalize]"]
lines.append("paths = \(self.paths)")
lines.append("subpathsToIgnore = \(self.subpathsToIgnore)")
lines.append("sourceLocale = \"\(self.sourceLocale)\"")
lines.append("harmonizeWithSource = \(self.harmonizeWithSource)")
lines.append("sortByKeys = \(self.sortByKeys)")
lines.append("separateWithEmptyLine = \(self.separateWithEmptyLine)")
return lines.joined(separator: "\n")
}
}