-
Notifications
You must be signed in to change notification settings - Fork 52
/
config.go
41 lines (38 loc) · 1020 Bytes
/
config.go
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
package formatter
import (
"io"
"log"
"strings"
)
// Config defines main application configs (requirements from user), like:
// where output will be delivered, desired output format, input file path, output file path
// and different output options
type Config struct {
Writer io.WriteCloser
OutputFormat OutputFormat
InputFileConfig InputFileConfig
OutputFile OutputFile
OutputOptions OutputOptions
ShowVersion bool
TemplatePath string
CustomOptions []string
CurrentVersion string
}
// CustomOptionsMap returns custom options provided in the CLI
func (c *Config) CustomOptionsMap() map[string]string {
m := map[string]string{}
for _, o := range c.CustomOptions {
split := strings.SplitN(o, "=", 2)
if len(split) != 2 {
log.Printf("custom option %s has wrong format", o)
continue
}
// An attempt to replace all problematic characters with underscores
r := strings.NewReplacer(
"-", "_",
" ", "_",
)
m[r.Replace(split[0])] = split[1]
}
return m
}