diff options
author | Slack Coder <slackcoder@server.ky> | 2023-10-18 17:27:00 -0500 |
---|---|---|
committer | Slack Coder <slackcoder@server.ky> | 2023-10-18 17:27:00 -0500 |
commit | 2be3a82f3a801a84c98a4de9c818ce8b0497135b (patch) | |
tree | 9fb89a6b10fddbb1560d895215b445813d3ea28c /vendor/github.com/pborman/getopt/v2/enum.go | |
parent | 2fda2161877e61e16b7f208ba1f92f650776cbe2 (diff) | |
download | pkgtools-go-todo.tar.xz |
move todos to project roottodo
Diffstat (limited to 'vendor/github.com/pborman/getopt/v2/enum.go')
-rw-r--r-- | vendor/github.com/pborman/getopt/v2/enum.go | 79 |
1 files changed, 0 insertions, 79 deletions
diff --git a/vendor/github.com/pborman/getopt/v2/enum.go b/vendor/github.com/pborman/getopt/v2/enum.go deleted file mode 100644 index 1ca6ff9..0000000 --- a/vendor/github.com/pborman/getopt/v2/enum.go +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright 2017 Google Inc. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package getopt - -import ( - "errors" - "fmt" - "sync" -) - -type enumValue string - -var ( - enumValuesMu sync.Mutex - enumValues = make(map[*enumValue]map[string]struct{}) -) - -func (s *enumValue) Set(value string, opt Option) error { - enumValuesMu.Lock() - es, ok := enumValues[s] - enumValuesMu.Unlock() - if !ok || es == nil { - return errors.New("this option has no values") - } - if _, ok := es[value]; !ok { - return errors.New("invalid value: " + value) - } - *s = enumValue(value) - return nil -} - -func (s *enumValue) String() string { - return string(*s) -} - -// Enum creates an option that can only be set to one of the enumerated strings -// passed in values. Passing nil or an empty slice results in an option that -// will always fail. If not "", value is the default value of the enum. If -// value is not listed in values then Enum will produce an error on standard -// error and then exit the program with a status of 1. -func Enum(name rune, values []string, value string, helpvalue ...string) *string { - return CommandLine.Enum(name, values, value, helpvalue...) -} - -func (s *Set) Enum(name rune, values []string, value string, helpvalue ...string) *string { - var p enumValue - p.define(values, value, &option{short: name}) - s.FlagLong(&p, "", name, helpvalue...) - return (*string)(&p) -} - -func EnumLong(name string, short rune, values []string, value string, helpvalue ...string) *string { - return CommandLine.EnumLong(name, short, values, value, helpvalue...) -} - -func (s *Set) EnumLong(name string, short rune, values []string, value string, helpvalue ...string) *string { - var p enumValue - p.define(values, value, &option{short: short, long: name}) - s.FlagLong(&p, name, short, helpvalue...) - return (*string)(&p) -} - -func (e *enumValue) define(values []string, def string, opt Option) { - m := make(map[string]struct{}) - for _, v := range values { - m[v] = struct{}{} - } - enumValuesMu.Lock() - enumValues[e] = m - enumValuesMu.Unlock() - if def != "" { - if err := e.Set(def, nil); err != nil { - fmt.Fprintf(stderr, "setting default for %s: %v\n", opt.Name(), err) - exit(1) - } - } -} |