diff --git a/README.md b/README.md index 3385e5d..afa53a7 100644 --- a/README.md +++ b/README.md @@ -16,20 +16,21 @@ If you don’t use Homebrew you can also install directly from source. Clone the ## Usage ``` -USAGE: make-colors [--ios] [--android] [--html] [--prefix ] [--output ] +USAGE: make-colors [--ios] [--android] [--html] [--prefix ] [--output ] [--dump] ARGUMENTS: The color list to process. Use - to process the standard input. OPTIONS: - --ios/--android/--html The formatter to use (default: ios) - --prefix Prefix for color names + --ios/--android/--html The formatter to use. (default: ios) + --prefix Prefix for color names. --output Output file to write. Use - for standard output. Default is the input file name with the appropriate file extension. If - the input is read from the standard input the default is standard - output. + the input is - the default is standard output. + Note that asset catalogs cannot be written to standard output. + --dump List read colors on console. -h, --help Show help information. ``` diff --git a/Sources/LibMakeColors/MakeColors.swift b/Sources/LibMakeColors/MakeColors.swift index 3140601..a2db649 100644 --- a/Sources/LibMakeColors/MakeColors.swift +++ b/Sources/LibMakeColors/MakeColors.swift @@ -60,6 +60,9 @@ public final class MakeColors: ParsableCommand, Context { @Option(help: HelpTexts.output) var output: String? + @Flag(help: "List read colors on console.") + var dump = false + public init() {} public func run() throws { @@ -68,19 +71,8 @@ public final class MakeColors: ParsableCommand, Context { let data = try scanner.colorList() - 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: ": " - ) - } + if dump { + try dump(data: data) } let generator = formatter.type.init(context: self) @@ -109,6 +101,23 @@ public final class MakeColors: ParsableCommand, Context { 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 { if shouldWriteToStdout { guard wrapper.isRegularFile, let contents = wrapper.regularFileContents else {