github.com/thriqon/involucro@v1.1.3/app/utils.go (about) 1 package app 2 3 import ( 4 "fmt" 5 "strings" 6 ) 7 8 type variablesValue map[string]string 9 10 func (v *variablesValue) String() string { 11 var items []string 12 for k, v := range *v { 13 items = append(items, fmt.Sprintf("%s=%s", k, v)) 14 } 15 return fmt.Sprintf("[%s]", strings.Join(items, " ")) 16 } 17 18 type errInvalidFormatForVariableAssignment string 19 20 func (e errInvalidFormatForVariableAssignment) Error() string { 21 return fmt.Sprintf("Invalid value [%s], expected value of the form: KEY=VALUE", string(e)) 22 } 23 24 func (v *variablesValue) Set(s string) error { 25 if *v == nil { 26 *v = make(map[string]string) 27 } 28 ss := strings.SplitN(s, "=", 2) 29 if len(ss) < 2 { 30 return errInvalidFormatForVariableAssignment(s) 31 } 32 (*v)[ss[0]] = ss[1] 33 return nil 34 }