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/error.go | |
parent | 2fda2161877e61e16b7f208ba1f92f650776cbe2 (diff) | |
download | pkgtools-go-todo.tar.xz |
move todos to project roottodo
Diffstat (limited to 'vendor/github.com/pborman/getopt/v2/error.go')
-rw-r--r-- | vendor/github.com/pborman/getopt/v2/error.go | 93 |
1 files changed, 0 insertions, 93 deletions
diff --git a/vendor/github.com/pborman/getopt/v2/error.go b/vendor/github.com/pborman/getopt/v2/error.go deleted file mode 100644 index 6f668a3..0000000 --- a/vendor/github.com/pborman/getopt/v2/error.go +++ /dev/null @@ -1,93 +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 "fmt" - -// An Error is returned by Getopt when it encounters an error. -type Error struct { - ErrorCode // General reason of failure. - Err error // The actual error. - Parameter string // Parameter passed to option, if any - Name string // Option that cause error, if any -} - -// Error returns the error message, implementing the error interface. -func (i *Error) Error() string { return i.Err.Error() } - -// An ErrorCode indicates what sort of error was encountered. -type ErrorCode int - -const ( - NoError = ErrorCode(iota) - UnknownOption // an invalid option was encountered - MissingParameter // the options parameter is missing - ExtraParameter // a value was set to a long flag - Invalid // attempt to set an invalid value -) - -func (e ErrorCode) String() string { - switch e { - case UnknownOption: - return "unknow option" - case MissingParameter: - return "missing argument" - case ExtraParameter: - return "unxpected value" - case Invalid: - return "error setting value" - } - return "unknown error" -} - -// unknownOption returns an Error indicating an unknown option was -// encountered. -func unknownOption(name interface{}) *Error { - i := &Error{ErrorCode: UnknownOption} - switch n := name.(type) { - case rune: - if n == '-' { - i.Name = "-" - } else { - i.Name = "-" + string(n) - } - case string: - i.Name = "--" + n - } - i.Err = fmt.Errorf("unknown option: %s", i.Name) - return i -} - -// missingArg returns an Error inidicating option o was not passed -// a required paramter. -func missingArg(o Option) *Error { - return &Error{ - ErrorCode: MissingParameter, - Name: o.Name(), - Err: fmt.Errorf("missing parameter for %s", o.Name()), - } -} - -// extraArg returns an Error inidicating option o was passed the -// unexpected paramter value. -func extraArg(o Option, value string) *Error { - return &Error{ - ErrorCode: ExtraParameter, - Name: o.Name(), - Parameter: value, - Err: fmt.Errorf("unexpected parameter passed to %s: %q", o.Name(), value), - } -} - -// setError returns an Error inidicating option o and the specified -// error while setting it to value. -func setError(o Option, value string, err error) *Error { - return &Error{ - ErrorCode: Invalid, - Name: o.Name(), - Parameter: value, - Err: err, - } -} |