vitess.io/vitess@v0.16.2/go/vt/topo/topoproto/flag.go (about) 1 /* 2 Copyright 2019 The Vitess 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 topoproto 18 19 import ( 20 "strings" 21 22 topodatapb "vitess.io/vitess/go/vt/proto/topodata" 23 ) 24 25 // TabletTypeListFlag implements the pflag.Value interface, for parsing a command-line comma-separated 26 // list of values into a slice of TabletTypes. 27 type TabletTypeListFlag []topodatapb.TabletType 28 29 // String is part of the pflag.Value interface. 30 func (ttlv *TabletTypeListFlag) String() string { 31 return strings.Join(MakeStringTypeList(*ttlv), ",") 32 } 33 34 // Set is part of the pflag.Value interface. 35 func (ttlv *TabletTypeListFlag) Set(v string) (err error) { 36 *ttlv, err = ParseTabletTypes(v) 37 return err 38 } 39 40 // Type is part of the pflag.Value interface. 41 func (ttlv *TabletTypeListFlag) Type() string { 42 return "strings" 43 } 44 45 // TabletTypeFlag implements the pflag.Value interface, for parsing a command-line value into a TabletType. 46 type TabletTypeFlag topodatapb.TabletType 47 48 // String is part of the pflag.Value interfaces. 49 func (ttf *TabletTypeFlag) String() string { 50 return topodatapb.TabletType(*ttf).String() 51 } 52 53 // Set is part of the pflag.Value interfaces. 54 func (ttf *TabletTypeFlag) Set(v string) error { 55 t, err := ParseTabletType(v) 56 *ttf = TabletTypeFlag(t) 57 return err 58 } 59 60 // Type is part of the pflag.Value interface. 61 func (*TabletTypeFlag) Type() string { return "topodatapb.TabletType" }