Add flag to dump read colors to console. Not very helpful if you want to use this in a pipeline

This commit is contained in:
Sven Weidauer 2020-12-31 20:26:32 +01:00
parent 90a3ed745f
commit 911db304ae
2 changed files with 28 additions and 18 deletions

View file

@ -16,20 +16,21 @@ If you dont use Homebrew you can also install directly from source. Clone the
## Usage ## Usage
``` ```
USAGE: make-colors <input> [--ios] [--android] [--html] [--prefix <prefix>] [--output <output>] USAGE: make-colors <input> [--ios] [--android] [--html] [--prefix <prefix>] [--output <output>] [--dump]
ARGUMENTS: ARGUMENTS:
<input> The color list to process. <input> The color list to process.
Use - to process the standard input. Use - to process the standard input.
OPTIONS: OPTIONS:
--ios/--android/--html The formatter to use (default: ios) --ios/--android/--html The formatter to use. (default: ios)
--prefix <prefix> Prefix for color names --prefix <prefix> Prefix for color names.
--output <output> Output file to write. --output <output> Output file to write.
Use - for standard output. Use - for standard output.
Default is the input file name with the appropriate file extension. If Default is the input file name with the appropriate file extension. If
the input is read from the standard input the default is standard the input is - the default is standard output.
output. Note that asset catalogs cannot be written to standard output.
--dump List read colors on console.
-h, --help Show help information. -h, --help Show help information.
``` ```

View file

@ -60,6 +60,9 @@ public final class MakeColors: ParsableCommand, Context {
@Option(help: HelpTexts.output) @Option(help: HelpTexts.output)
var output: String? var output: String?
@Flag(help: "List read colors on console.")
var dump = false
public init() {} public init() {}
public func run() throws { public func run() throws {
@ -68,19 +71,8 @@ public final class MakeColors: ParsableCommand, Context {
let data = try scanner.colorList() let data = try scanner.colorList()
for (key, color) in data.sorted() { if dump {
let resolved = try data.resolve(key) try dump(data: data)
switch color {
case .color:
print(key.insertCamelCaseSeparators(), resolved, separator: ": ")
case let .reference(referenced):
print(
"\(key.insertCamelCaseSeparators()) (@\(referenced.insertCamelCaseSeparators()))",
resolved,
separator: ": "
)
}
} }
let generator = formatter.type.init(context: self) let generator = formatter.type.init(context: self)
@ -109,6 +101,23 @@ public final class MakeColors: ParsableCommand, Context {
return input return input
} }
func dump(data: [String: ColorDef]) throws {
for (key, color) in data.sorted() {
let resolved = try data.resolve(key)
switch color {
case .color:
print(key.insertCamelCaseSeparators(), resolved, separator: ": ")
case let .reference(referenced):
print(
"\(key.insertCamelCaseSeparators()) (@\(referenced.insertCamelCaseSeparators()))",
resolved,
separator: ": "
)
}
}
}
func writeOutput(_ wrapper: FileWrapper) throws { func writeOutput(_ wrapper: FileWrapper) throws {
if shouldWriteToStdout { if shouldWriteToStdout {
guard wrapper.isRegularFile, let contents = wrapper.regularFileContents else { guard wrapper.isRegularFile, let contents = wrapper.regularFileContents else {