Refactor exec and buildformat to improve type safety and clearer imports
**What** - Create and move exec commands to a new exec package, this will make it easier to reuse in the future "install" command - Move git related commands to the versioncontrol package to keep the git related commands together and easy to find. - Implement flags interfaces for the BuildFormat so that the flags package can set and validate this value directly and then we can directly pass this value around to improve type safety in the throughout - Renames the `tag` variable to `tagFormat` to improve readability, the value is not directly the tag value and this could be confusing before. Signed-off-by: Lucas Roesler <roesler.lucas@gmail.com>
This commit is contained in:
committed by
Alex Ellis
parent
027157327f
commit
39c93555e4
@@ -1,9 +1,11 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// BuildFormat defines the docker image tag format that is used during the build process
|
||||
type BuildFormat int
|
||||
|
||||
// DefaultFormat as defined in the YAML file or appending :latest
|
||||
@@ -18,6 +20,48 @@ const BranchAndSHAFormat BuildFormat = 2
|
||||
// DescribeFormat uses the git-describe output as the docker tag
|
||||
const DescribeFormat BuildFormat = 3
|
||||
|
||||
// Type implements pflag.Value
|
||||
func (i *BuildFormat) Type() string {
|
||||
return "string"
|
||||
}
|
||||
|
||||
// String implements Stringer
|
||||
func (i *BuildFormat) String() string {
|
||||
if i == nil {
|
||||
return "latest"
|
||||
}
|
||||
|
||||
switch *i {
|
||||
case DefaultFormat:
|
||||
return "latest"
|
||||
case SHAFormat:
|
||||
return "sha"
|
||||
case BranchAndSHAFormat:
|
||||
return "branch"
|
||||
case DescribeFormat:
|
||||
return "describe"
|
||||
default:
|
||||
return "latest"
|
||||
}
|
||||
}
|
||||
|
||||
// Set implements pflag.Value
|
||||
func (l *BuildFormat) Set(value string) error {
|
||||
switch strings.ToLower(value) {
|
||||
case "", "default", "latest":
|
||||
*l = DefaultFormat
|
||||
case "sha":
|
||||
*l = SHAFormat
|
||||
case "branch":
|
||||
*l = BranchAndSHAFormat
|
||||
case "describe":
|
||||
*l = DescribeFormat
|
||||
default:
|
||||
return fmt.Errorf("unknown image tag format: '%s'", value)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// BuildImageName builds a Docker image tag for build, push or deploy
|
||||
func BuildImageName(format BuildFormat, image string, version string, branch string) string {
|
||||
imageVal := image
|
||||
|
||||
Reference in New Issue
Block a user