github.com/aristanetworks/goarista@v0.0.0-20240514173732-cca2755bbd44/flag/string_array.go (about)

     1  // Copyright (c) 2019 Arista Networks, Inc.
     2  // Use of this source code is governed by the Apache License 2.0
     3  // that can be found in the COPYING file.
     4  
     5  package flag
     6  
     7  import "fmt"
     8  
     9  // StringArrayOption is a type used to provide string options via command line flags.
    10  type StringArrayOption []string
    11  
    12  // String is the method to format the flag's value, part of the flag.Value interface.
    13  // The String method's output will be used in diagnostics.
    14  func (a *StringArrayOption) String() string {
    15  	return fmt.Sprintf("%#v", *a)
    16  }
    17  
    18  // Set is the method to set the flag value, part of the flag.Value interface.
    19  // Set's argument is a string to be parsed to set the flag.
    20  func (a *StringArrayOption) Set(value string) error {
    21  	*a = append(*a, value)
    22  	return nil
    23  }