Improve usage message and add to README

This commit is contained in:
Sven Weidauer 2020-12-31 19:44:26 +01:00
parent abc0ef910d
commit 13f985c0a4
2 changed files with 44 additions and 5 deletions

View file

@ -13,6 +13,26 @@ brew install make-colors
If you dont use Homebrew you can also install directly from source. Clone the repository or download the release and run `make install` inside the working copy. If you dont use Homebrew you can also install directly from source. Clone the repository or download the release and run `make install` inside the working copy.
## Usage
```
USAGE: make-colors <input> [--ios] [--android] [--html] [--prefix <prefix>] [--output <output>]
ARGUMENTS:
<input> The color list to process.
Use - to process the standard input.
OPTIONS:
--ios/--android/--html The formatter to use (default: ios)
--prefix <prefix> Prefix for color names
--output <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.
-h, --help Show help information.
```
## Input format ## Input format
Each line in your input contains one color definition. That is a name followed by the actual color. We support RGB colors in a few formats similar to CSS: Each line in your input contains one color definition. That is a name followed by the actual color. We support RGB colors in a few formats similar to CSS:

View file

@ -28,17 +28,36 @@ enum Errors: Error {
case cannotReadStdin case cannotReadStdin
} }
enum HelpTexts {
static let input = ArgumentHelp(
"The color list to process.",
discussion: """
Use - to process the standard input.
"""
)
static let output = ArgumentHelp(
"Output file to write.",
discussion: """
Use - for standard output.
Default is the input file name with the appropriate file extension. \
If the input is - the default is standard output.
Note that asset catalogs cannot be written to standard output.
"""
)
}
public final class MakeColors: ParsableCommand, Context { public final class MakeColors: ParsableCommand, Context {
@Argument(help: "The color list to proces") @Argument(help: HelpTexts.input)
var input: String var input: String
@Flag(help: "The formatter to use") @Flag(help: "The formatter to use.")
private var formatter = GeneratorOption.allCases[0] private var formatter = GeneratorOption.allCases[0]
@Option(help: "Prefix for color names") @Option(help: "Prefix for color names.")
var prefix: String? var prefix: String?
@Option(help: "Output file") @Option(help: HelpTexts.output)
var output: String? var output: String?
public init() {} public init() {}
@ -103,7 +122,7 @@ public final class MakeColors: ParsableCommand, Context {
} }
} }
var shouldWriteToStdout: Bool { input == "-" && output == nil } var shouldWriteToStdout: Bool { output == "-" || (input == "-" && output == nil) }
func outputURL(extension: String) -> URL { func outputURL(extension: String) -> URL {
if let output = output { if let output = output {