| // Copyright 2022 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| package flagutil |
| |
| import ( |
| "strings" |
| ) |
| |
| // RepeatedStringValue is an alias for a string slice that's usable as the |
| // target for a flag variable. |
| // |
| // Example: |
| // |
| // type fooCmd struct { |
| // strings flagutil.RepeatedStringValue |
| // } |
| // |
| // func (c *fooCmd) Init(...) { |
| // ... |
| // c.Flags.Var(&c.strings, "s", "Repeated string flag.") |
| // } |
| // |
| // The resulting CLI can then be invoked like: |
| // |
| // foo -s arg1 -s arg2 -s arg3 |
| // |
| // and the resulting value will be []string{"arg1", "arg2", "arg3"}. |
| type RepeatedStringValue []string |
| |
| func (sl *RepeatedStringValue) String() string { |
| return strings.Join(*sl, ", ") |
| } |
| |
| func (sl *RepeatedStringValue) Set(s string) error { |
| *sl = append(*sl, s) |
| return nil |
| } |