github.com/chenbh/concourse/v6@v6.4.2/fly/commands/internal/flaghelpers/input_pair_flag.go (about) 1 package flaghelpers 2 3 import ( 4 "fmt" 5 "path/filepath" 6 "strings" 7 ) 8 9 type InputPairFlag struct { 10 Name string 11 Path string 12 } 13 14 func (pair *InputPairFlag) UnmarshalFlag(value string) error { 15 vs := strings.SplitN(value, "=", 2) 16 if len(vs) != 2 { 17 return fmt.Errorf("invalid input pair '%s' (must be name=path)", value) 18 } 19 20 matches, err := filepath.Glob(vs[1]) 21 if err != nil { 22 return fmt.Errorf("failed to expand path '%s': %s", vs[1], err) 23 } 24 25 if len(matches) == 0 { 26 return fmt.Errorf("path '%s' does not exist", vs[1]) 27 } 28 29 if len(matches) > 1 { 30 return fmt.Errorf("path '%s' resolves to multiple entries: %s", vs[1], strings.Join(matches, ", ")) 31 } 32 33 pair.Name = vs[0] 34 pair.Path = matches[0] 35 36 return nil 37 }