mirror of
https://github.com/hashicorp/packer.git
synced 2026-09-18 22:11:39 -04:00
* [COMPLIANCE] Add/Update Copyright Headers * make generate update * make generate --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com> Co-authored-by: sanya <[email protected]> Co-authored-by: Sanya <[email protected]>
32 lines
612 B
Go
32 lines
612 B
Go
// Copyright IBM Corp. 2024, 2026
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package enumflag
|
|
|
|
import "fmt"
|
|
|
|
type enumFlag struct {
|
|
target *string
|
|
options []string
|
|
}
|
|
|
|
// New returns a flag.Value implementation for parsing flags with a one-of-a-set value
|
|
func New(target *string, options ...string) *enumFlag {
|
|
return &enumFlag{target: target, options: options}
|
|
}
|
|
|
|
func (f *enumFlag) String() string {
|
|
return *f.target
|
|
}
|
|
|
|
func (f *enumFlag) Set(value string) error {
|
|
for _, v := range f.options {
|
|
if v == value {
|
|
*f.target = value
|
|
return nil
|
|
}
|
|
}
|
|
|
|
return fmt.Errorf("expected one of %q", f.options)
|
|
}
|