github.com/yrj2011/jx-test-infra@v0.0.0-20190529031832-7a2065ee98eb/prow/flagutil/flagutil.go (about) 1 /* 2 Copyright 2018 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package flagutil 18 19 import "strings" 20 21 type Strings struct { 22 vals []string 23 beenSet bool 24 } 25 26 // NewStrings returns a Strings struct that defaults to the value of def if left 27 // unset. 28 func NewStrings(def ...string) Strings { 29 return Strings{ 30 vals: def, 31 beenSet: false, 32 } 33 } 34 35 func (s *Strings) Strings() []string { 36 return s.vals 37 } 38 39 func (s *Strings) String() string { 40 return strings.Join(s.vals, ",") 41 } 42 43 // Set records the value passed 44 func (s *Strings) Set(value string) error { 45 if !s.beenSet { 46 s.beenSet = true 47 // Value is being set, don't use default. 48 s.vals = nil 49 } 50 s.vals = append(s.vals, value) 51 return nil 52 }