| OLD | NEW |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package stringsetflag | 5 package stringsetflag |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "flag" | 8 "flag" |
| 9 "fmt" | 9 "fmt" |
| 10 "os" | 10 "os" |
| 11 ) | 11 ) |
| 12 | 12 |
| 13 // Example demonstrates how to use flagenum to create bindings for a custom | 13 // Example demonstrates how to use stringlistflag. |
| 14 // type. | |
| 15 func Example() { | 14 func Example() { |
| 16 sset := Flag{} | 15 sset := Flag{} |
| 17 | 16 |
| 18 fs := flag.NewFlagSet("test", flag.ContinueOnError) | 17 fs := flag.NewFlagSet("test", flag.ContinueOnError) |
| 19 fs.Var(&sset, "color", "favorite color, may be repeated.") | 18 fs.Var(&sset, "color", "favorite color, may be repeated.") |
| 20 fs.SetOutput(os.Stdout) | 19 fs.SetOutput(os.Stdout) |
| 21 | 20 |
| 22 fs.PrintDefaults() | 21 fs.PrintDefaults() |
| 23 | 22 |
| 24 // Flag parsing. | 23 // Flag parsing. |
| 25 fs.Parse([]string{"-color", "Violet", "-color", "Red", "-color", "Violet
"}) | 24 fs.Parse([]string{"-color", "Violet", "-color", "Red", "-color", "Violet
"}) |
| 26 fmt.Printf("Value is: %s\n", sset) | 25 fmt.Printf("Value is: %s\n", sset) |
| 27 | 26 |
| 28 fmt.Println("Likes Blue:", sset.Data.Has("Blue")) | 27 fmt.Println("Likes Blue:", sset.Data.Has("Blue")) |
| 29 fmt.Println("Likes Red:", sset.Data.Has("Red")) | 28 fmt.Println("Likes Red:", sset.Data.Has("Red")) |
| 30 | 29 |
| 31 // Output: | 30 // Output: |
| 32 // -color value | 31 // -color value |
| 33 // favorite color, may be repeated. | 32 // favorite color, may be repeated. |
| 34 // Value is: Red,Violet | 33 // Value is: Red,Violet |
| 35 // Likes Blue: false | 34 // Likes Blue: false |
| 36 // Likes Red: true | 35 // Likes Red: true |
| 37 } | 36 } |
| OLD | NEW |