github.com/sudo-bmitch/version-bump@v0.0.0-20240503123857-70b0e3f646dd/internal/source/manual.go (about) 1 package source 2 3 import ( 4 "fmt" 5 6 "github.com/sudo-bmitch/version-bump/internal/config" 7 ) 8 9 type manual struct { 10 conf config.Source 11 } 12 13 func newManual(conf config.Source) Source { 14 if conf.Args == nil { 15 conf.Args = map[string]string{} 16 } 17 if _, ok := conf.Args["Version"]; !ok { 18 conf.Args["Version"] = "{{ .ScanMatch.Version }}" 19 } 20 return manual{conf: conf} 21 } 22 23 func (m manual) Get(data config.SourceTmplData) (string, error) { 24 confExp, err := m.conf.ExpandTemplate(data) 25 if err != nil { 26 return "", fmt.Errorf("failed to expand template: %w", err) 27 } 28 if _, ok := confExp.Args["Version"]; !ok { 29 return "", fmt.Errorf("manual source is missing a version arg") 30 } 31 verData := VersionTmplData{ 32 Version: confExp.Args["Version"], 33 } 34 return procResult(confExp, verData) 35 } 36 37 func (m manual) Key(data config.SourceTmplData) (string, error) { 38 confExp, err := m.conf.ExpandTemplate(data) 39 if err != nil { 40 return "", fmt.Errorf("failed to expand template: %w", err) 41 } 42 return confExp.Key, nil 43 }