spud/cli/build.go
Marc Cataford 17221855cc
Some checks failed
/ build (push) Has been cancelled
feat: add explicit flag / arg definitions
2024-09-28 21:49:46 -04:00

43 lines
976 B
Go

package cli
import (
"fmt"
"github.com/spf13/cobra"
"log"
podman "spud/podman"
service_definition "spud/service_definition"
)
func getBuildCommand() *cobra.Command {
build := &cobra.Command{
Use: "build",
Short: "Build service images.",
RunE: func(cmd *cobra.Command, args []string) error {
pathProvided, err := cmd.PersistentFlags().GetString("definition")
if err != nil {
return fmt.Errorf("%+v", err)
}
def, err := service_definition.GetServiceDefinitionFromFile(pathProvided)
if err != nil {
return fmt.Errorf("Failed to read service definition from file: %+v", err)
}
imagesToBuild := def.Build.Images
if len(imagesToBuild) == 0 {
log.Print("No images defined - nothing to build!")
}
for _, imageDef := range imagesToBuild {
podman.Build(imageDef)
}
return nil
},
}
build.PersistentFlags().StringP("definition", "d", "./service.yml", "Path to the service definition to use.")
return build
}