with more generic way, but still wonky

This commit is contained in:
2022-10-29 23:33:46 +02:00
parent 0838bc5a56
commit a872bad97d
4 changed files with 14 additions and 16 deletions

View File

@@ -1,19 +1,17 @@
package cli
import (
"errors"
"fmt"
"log"
"os"
"git.front.kjuulh.io/kjuulh/dagger-go/internal"
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/tasks"
"github.com/spf13/cobra"
)
func Build() *cobra.Command {
var (
imageTag string
mainGoPath string
)
func Build(mainGoPath string, imageTag string) *cobra.Command {
cmd := &cobra.Command{
Use: "build",
RunE: func(cmd *cobra.Command, args []string) error {
@@ -21,6 +19,14 @@ func Build() *cobra.Command {
return err
}
if imageTag == "" {
repoName := os.Getenv("DRONE_REPO_NAME")
if repoName == "" {
return errors.New("could not find DRONE_REPO_NAME")
}
imageTag = fmt.Sprintf("harbor.front.kjuulh.io/library/%s", repoName)
}
ctx := cmd.Context()
log.Printf("Building image: %s\n", imageTag)
@@ -35,10 +41,5 @@ func Build() *cobra.Command {
},
}
cmd.PersistentFlags().StringVar(&imageTag, "image-tag", "", "the url for which to tag the docker image, defaults to private url, with repo as image name")
cmd.MarkPersistentFlagRequired("image-tag")
cmd.PersistentFlags().StringVar(&mainGoPath, "main-path", "main.go", "main.go path")
return cmd
}