diff options
author | Thomas Voss <mail@thomasvoss.com> | 2023-12-05 01:32:52 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2023-12-05 01:32:52 +0100 |
commit | 264780bb60dda33e8d06c48be5f1991212d62a9a (patch) | |
tree | 684d61e3e7aaddf73ce4e7c6fc731f72a23a7fac /v2/err.go | |
parent | 799bb3be1d099ce6979cd6baa8b84acc507130bd (diff) |
Diffstat (limited to 'v2/err.go')
-rw-r--r-- | v2/err.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/v2/err.go b/v2/err.go new file mode 100644 index 0000000..23692fa --- /dev/null +++ b/v2/err.go @@ -0,0 +1,31 @@ +package opts + +import "fmt" + +// A BadOptionError describes an option that the user attempted to pass +// which the developer did not register. +type BadOptionError struct { + r rune + s string +} + +func (e BadOptionError) Error() string { + if e.r != 0 { + return fmt.Sprintf("unknown option ‘-%c’", e.r) + } + return fmt.Sprintf("unknown option ‘--%s’", e.s) +} + +// A NoArgumentError describes an option that the user attempted to pass +// without an argument, which required an argument. +type NoArgumentError struct { + r rune + s string +} + +func (e NoArgumentError) Error() string { + if e.r != 0 { + return fmt.Sprintf("expected argument for option ‘-%c’", e.r) + } + return fmt.Sprintf("expected argument for option ‘--%s’", e.s) +} |