Skip to content

Commit e7c3709

Browse files
committed
add onlycolor option
1 parent 04287c0 commit e7c3709

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

cmd/svgpattern/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ import (
1717
// quelques variables globales
1818
var version = "dev"
1919

20+
// onlycolor is a flag to only output the color
21+
var onlycolor bool
22+
2023
// Aide affiche l'aide d'utilisation
2124
func help() {
2225
var out = os.Stderr
@@ -118,6 +121,7 @@ func generatorFromParameters() svgpattern.Generator {
118121
flag.StringVarP(&lightness, "lightness", "l", "", "The lightness variation (using HSL colors). Value format is '[value][~deviation]' or 'min:max'.")
119122
flag.StringVarP(&rotate, "rotate", "r", "", "Rotation angle in degree. Value format is '[value][~deviation]' or 'min:max'.")
120123
flag.StringVarP(&scale, "scale", "s", "", "Scale factor. Value format is '[value][~deviation]' or 'min:max'.")
124+
flag.BoolVar(&onlycolor, "onlycolor", false, "Only output the color.")
121125
//parse the flags
122126
flag.Parse()
123127
// chack if parameters were provided
@@ -185,6 +189,10 @@ func log(format string, a ...interface{}) (n int, err error) {
185189
// Prints pattern's SVG string with a specific background color
186190
func main() {
187191
g := generatorFromParameters()
192+
if onlycolor {
193+
fmt.Println(g.Color())
194+
return
195+
}
188196
svg, ok := g.Generate()
189197
if !ok {
190198
log("There are some errors : %v", g.Errors())

pattern.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ type Generator interface {
6868
Options(...Option)
6969
Generate() (svg []byte, ok bool)
7070
Errors() []string
71+
Color() string
7172
}
7273

7374
// Errors provide the error messages generated during the initialization/generation process.
@@ -106,6 +107,11 @@ func (g *generator) Generate() (svg []byte, ok bool) {
106107
return result.Bytes(), len(g.errors) == 0
107108
}
108109

110+
// Color returns the color used to generate the pattern as hex string.
111+
func (g *generator) Color() string {
112+
return g.color.Hex()
113+
}
114+
109115
// An Option is a function that customize the Generator.
110116
type Option func(*generator)
111117

0 commit comments

Comments
 (0)