aboutsummaryrefslogtreecommitdiff
path: root/err.go
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2023-11-30 00:59:30 +0100
committerThomas Voss <mail@thomasvoss.com> 2023-11-30 00:59:30 +0100
commit9fb540642acc6dfcc6816291a832a8ea56973f09 (patch)
tree15910ae83f43a033368a6cffc5195c12d5c2772f /err.go
parent7fbe5d6731df8f6b8601431d8fc42c166c0e0e00 (diff)
Add long-option support
Diffstat (limited to 'err.go')
-rw-r--r--err.go20
1 files changed, 16 insertions, 4 deletions
diff --git a/err.go b/err.go
index cbe96b4..23692fa 100644
--- a/err.go
+++ b/err.go
@@ -4,16 +4,28 @@ import "fmt"
// A BadOptionError describes an option that the user attempted to pass
// which the developer did not register.
-type BadOptionError rune
+type BadOptionError struct {
+ r rune
+ s string
+}
func (e BadOptionError) Error() string {
- return fmt.Sprintf("unknown option ‘%c’", e)
+ 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 rune
+type NoArgumentError struct {
+ r rune
+ s string
+}
func (e NoArgumentError) Error() string {
- return fmt.Sprintf("expected argument for option ‘%c’", e)
+ if e.r != 0 {
+ return fmt.Sprintf("expected argument for option ‘-%c’", e.r)
+ }
+ return fmt.Sprintf("expected argument for option ‘--%s’", e.s)
}