diff options
author | Thomas Voss <mail@thomasvoss.com> | 2023-11-30 00:59:30 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2023-11-30 00:59:30 +0100 |
commit | 9fb540642acc6dfcc6816291a832a8ea56973f09 (patch) | |
tree | 15910ae83f43a033368a6cffc5195c12d5c2772f /err.go | |
parent | 7fbe5d6731df8f6b8601431d8fc42c166c0e0e00 (diff) |
Add long-option support
Diffstat (limited to 'err.go')
-rw-r--r-- | err.go | 20 |
1 files changed, 16 insertions, 4 deletions
@@ -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) } |