github.com/vchain-us/vcn@v0.9.11-0.20210921212052-a2484d23c0b3/pkg/cmd/sign/opts.go (about) 1 /* 2 * Copyright (c) 2018-2020 vChain, Inc. All Rights Reserved. 3 * This software is released under GPL3. 4 * The full license information can be found under: 5 * https://www.gnu.org/licenses/gpl-3.0.en.html 6 * 7 */ 8 9 package sign 10 11 import ( 12 "encoding/json" 13 "strings" 14 ) 15 16 type mapOpts map[string]string 17 18 // Set adds the input value to the map, by splitting on '='. 19 func (m mapOpts) Set(value string) error { 20 vals := strings.SplitN(value, "=", 2) 21 if len(vals) == 1 { 22 m[vals[0]] = "" 23 } else { 24 m[vals[0]] = vals[1] 25 } 26 return nil 27 } 28 29 func (m mapOpts) String() string { 30 if len(m) < 1 { 31 return "" 32 } 33 b, _ := json.Marshal(m) 34 return string(b) 35 } 36 37 func (m mapOpts) Type() string { 38 return "key=value" 39 } 40 41 func (m mapOpts) StringToInterface() map[string]interface{} { 42 r := map[string]interface{}{} 43 for k, v := range m { 44 r[k] = v 45 } 46 return r 47 } 48 49 func (m mapOpts) KeysToValues() []string { 50 var as []string 51 for k := range m { 52 as = append(as, k) 53 } 54 return as 55 }