-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9e01ba
commit 7f949ae
Showing
3 changed files
with
51 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package flags | ||
|
||
import "fmt" | ||
|
||
type enum struct { | ||
target *string | ||
options []string | ||
} | ||
|
||
func NewEnum(target *string, options ...string) *enum { | ||
return &enum{target: target, options: options} | ||
} | ||
|
||
func (f *enum) String() string { | ||
return *f.target | ||
} | ||
|
||
func (f *enum) Set(value string) error { | ||
for _, v := range f.options { | ||
if v == value { | ||
*f.target = value | ||
return nil | ||
} | ||
} | ||
|
||
return fmt.Errorf("expected one of the following %q", f.options) | ||
} |