vitess.io/vitess@v0.16.2/go/cmd/vtctldclient/cli/pflag.go (about)

     1  /*
     2  Copyright 2021 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 cli
    18  
    19  import (
    20  	"github.com/spf13/pflag"
    21  
    22  	"vitess.io/vitess/go/flagutil"
    23  	"vitess.io/vitess/go/vt/topo/topoproto"
    24  
    25  	topodatapb "vitess.io/vitess/go/vt/proto/topodata"
    26  )
    27  
    28  // StringMapValue augments flagutil.StringMapValue so it can be used as a
    29  // pflag.Value.
    30  type StringMapValue struct {
    31  	flagutil.StringMapValue
    32  }
    33  
    34  // Type is part of the pflag.Value interface.
    35  func (v *StringMapValue) Type() string {
    36  	return "cli.StringMapValue"
    37  }
    38  
    39  // KeyspaceTypeFlag adds the pflag.Value interface to a topodatapb.KeyspaceType.
    40  type KeyspaceTypeFlag topodatapb.KeyspaceType
    41  
    42  var _ pflag.Value = (*KeyspaceTypeFlag)(nil)
    43  
    44  // Set is part of the pflag.Value interface.
    45  func (v *KeyspaceTypeFlag) Set(arg string) error {
    46  	kt, err := topoproto.ParseKeyspaceType(arg)
    47  	if err != nil {
    48  		return err
    49  	}
    50  
    51  	*v = KeyspaceTypeFlag(kt)
    52  
    53  	return nil
    54  }
    55  
    56  // String is part of the pflag.Value interface.
    57  func (v *KeyspaceTypeFlag) String() string {
    58  	return topoproto.KeyspaceTypeString(topodatapb.KeyspaceType(*v))
    59  }
    60  
    61  // Type is part of the pflag.Value interface.
    62  func (v *KeyspaceTypeFlag) Type() string {
    63  	return "cli.KeyspaceTypeFlag"
    64  }