Merge "Fixed TODO in package config"

This commit is contained in:
Zuul 2020-09-01 22:17:51 +00:00 committed by Gerrit Code Review
commit eaa66fded7
2 changed files with 36 additions and 7 deletions

View File

@ -239,3 +239,31 @@ func (e ErrUnknownManagementType) Error() string {
return fmt.Sprintf("Unknown management type '%s'. Known types include '%s' and '%s'.", e.Type,
redfish.ClientType, redfishdell.ClientType)
}
// ErrMissingManifestName is returned when manifest name is empty
type ErrMissingManifestName struct {
}
func (e ErrMissingManifestName) Error() string {
return "missing manifest name"
}
// ErrMissingFlag is returned when flag is not provided
type ErrMissingFlag struct {
FlagName string
}
func (e ErrMissingFlag) Error() string {
return fmt.Sprintf("missing flag, specify a --%s to embed", e.FlagName)
}
// ErrCheckFile is returned if there is error when checking file on FS
type ErrCheckFile struct {
FlagName string
Path string
InternalErr error
}
func (e ErrCheckFile) Error() string {
return fmt.Sprintf("could not read %s data from '%s': %v", e.FlagName, e.Path, e.InternalErr)
}

View File

@ -17,7 +17,6 @@ limitations under the License.
package config
import (
"fmt"
"os"
"opendev.org/airship/airshipctl/pkg/errors"
@ -77,8 +76,6 @@ type ManifestOptions struct {
// is possible to create (and validate) these objects without using the command
// line.
// TODO(howell): strongly type the errors in this file
// Validate checks for the possible authentication values and returns
// Error when invalid value or incompatible choice of values given
func (o *AuthInfoOptions) Validate() error {
@ -162,10 +159,14 @@ func (o *ClusterOptions) Validate() error {
func checkExists(flagName, path string) error {
if path == "" {
return fmt.Errorf("you must specify a --%s to embed", flagName)
return ErrMissingFlag{FlagName: flagName}
}
if _, err := os.Stat(path); err != nil {
return fmt.Errorf("could not read %s data from '%s': %v", flagName, path, err)
return ErrCheckFile{
FlagName: flagName,
Path: path,
InternalErr: err,
}
}
return nil
}
@ -174,10 +175,10 @@ func checkExists(flagName, path string) error {
// Error when invalid value or incompatible choice of values given
func (o *ManifestOptions) Validate() error {
if o.Name == "" {
return fmt.Errorf("you must specify a non-empty Manifest name")
return ErrMissingManifestName{}
}
if o.RemoteRef != "" {
return fmt.Errorf("repository checkout by RemoteRef is not yet implemented\n%w", errors.ErrNotImplemented{})
return errors.ErrNotImplemented{What: "repository checkout by RemoteRef"}
}
if o.IsPrimary && o.RepoName == "" {
return ErrMissingRepositoryName{}