-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add flag validation error util * remove unused variable * fix formatting * cleanup signal unit * CI: add newer Go versions to test against * CI: bump versions of Github actions
- Loading branch information
1 parent
03555ec
commit 70f7053
Showing
6 changed files
with
61 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package flag | ||
|
||
import "fmt" | ||
|
||
// ValidationError provides the ability to create constant errors for run.Group | ||
// validation errors, e.g. incorrect flag values. | ||
type ValidationError string | ||
|
||
// Error implements the built-in error interface. | ||
func (v ValidationError) Error() string { return string(v) } | ||
|
||
// NewValidationError provides a convenient helper function to create flag | ||
// validation errors usable by run.Config implementations. | ||
func NewValidationError(flag string, reason error) error { | ||
return fmt.Errorf(FlagErr, flag, reason) | ||
} | ||
|
||
const ( | ||
// FlagErr can be used as formatting string for flag related validation | ||
// errors where the first variable lists the flag name and the second | ||
// variable is the actual error. | ||
FlagErr = "--%s error: %w" | ||
|
||
// ErrRequired is returned when required config options are not provided. | ||
ErrRequired ValidationError = "required" | ||
|
||
// ErrInvalidPath is returned when a path config option is invalid. | ||
ErrInvalidPath ValidationError = "invalid path" | ||
|
||
// ErrInvalidVal is returned when the value passed into a flag argument is invalid. | ||
ErrInvalidVal ValidationError = "invalid value" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters