...

Source file src/github.com/grpc-ecosystem/grpc-gateway/v2/utilities/string_array_flag.go

Documentation: github.com/grpc-ecosystem/grpc-gateway/v2/utilities

     1  package utilities
     2  
     3  import (
     4  	"flag"
     5  	"strings"
     6  )
     7  
     8  // flagInterface is an cut down interface to `flag`
     9  type flagInterface interface {
    10  	Var(value flag.Value, name string, usage string)
    11  }
    12  
    13  // StringArrayFlag defines a flag with the specified name and usage string.
    14  // The return value is the address of a `StringArrayFlags` variable that stores the repeated values of the flag.
    15  func StringArrayFlag(f flagInterface, name string, usage string) *StringArrayFlags {
    16  	value := &StringArrayFlags{}
    17  	f.Var(value, name, usage)
    18  	return value
    19  }
    20  
    21  // StringArrayFlags is a wrapper of `[]string` to provider an interface for `flag.Var`
    22  type StringArrayFlags []string
    23  
    24  // String returns a string representation of `StringArrayFlags`
    25  func (i *StringArrayFlags) String() string {
    26  	return strings.Join(*i, ",")
    27  }
    28  
    29  // Set appends a value to `StringArrayFlags`
    30  func (i *StringArrayFlags) Set(value string) error {
    31  	*i = append(*i, value)
    32  	return nil
    33  }
    34  

View as plain text