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