github.com/searKing/golang/go@v1.2.117/flag/example_test.go (about) 1 // Copyright 2020 The searKing Author. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package flag_test 6 7 import ( 8 "flag" 9 "fmt" 10 "os" 11 12 flag_ "github.com/searKing/golang/go/flag" 13 ) 14 15 func ExampleStringSliceVar() { 16 var infos []string 17 18 ResetForTesting(nil) 19 fs := flag.NewFlagSet("demo", flag.ContinueOnError) 20 fs.SetOutput(os.Stdout) 21 flag_.StringSliceVarWithFlagSet(fs, &infos, "i", []string{"hello", "world"}, "info arrays") 22 fs.PrintDefaults() 23 fmt.Printf("infos before parse: %q\n", infos) 24 _ = fs.Parse([]string{"-i", "golang", "-i", "flag", "-i", "string slice"}) 25 fmt.Printf("infos after parse: %q\n", infos) 26 27 // Output: 28 // -i value 29 // info arrays (default ["hello" "world"]) 30 // infos before parse: ["hello" "world"] 31 // infos after parse: ["golang" "flag" "string slice"] 32 33 }