Skip to content

Instantly share code, notes, and snippets.

@nikolaydubina
Created June 9, 2023 22:36
Show Gist options
  • Save nikolaydubina/cd1c184ddd7cee31a468c8e39e8f34ac to your computer and use it in GitHub Desktop.
Save nikolaydubina/cd1c184ddd7cee31a468c8e39e8f34ac to your computer and use it in GitHub Desktop.
// slice of strings as CLI argument 🐹
// https://pkg.go.dev/flag#Value
package main
import (
"flag"
"log"
)
type arrayFlags []string
func (i *arrayFlags) String() string {
return "my string representation"
}
func (i *arrayFlags) Set(value string) error {
*i = append(*i, value)
return nil
}
var myFlags arrayFlags
func main() {
flag.Var(&myFlags, "list1", "Some description for this param.")
flag.Parse()
for _, q := range myFlags {
log.Println(q)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment