Created
June 9, 2023 22:36
-
-
Save nikolaydubina/cd1c184ddd7cee31a468c8e39e8f34ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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