bust/pkg/cli/cli.go

42 lines
823 B
Go
Raw Normal View History

2022-10-29 18:32:51 +02:00
package cli
2022-10-29 18:00:16 +02:00
import (
"log"
2022-10-29 22:23:06 +02:00
"git.front.kjuulh.io/kjuulh/dagger-go/internal"
2022-10-29 19:06:50 +02:00
"git.front.kjuulh.io/kjuulh/dagger-go/pkg/tasks"
2022-10-29 18:00:16 +02:00
"github.com/spf13/cobra"
)
2022-10-29 22:23:06 +02:00
func Build() *cobra.Command {
2022-10-29 18:00:16 +02:00
var (
imageTag string
)
cmd := &cobra.Command{
Use: "build",
RunE: func(cmd *cobra.Command, args []string) error {
if err := cmd.ParseFlags(args); err != nil {
return err
}
2022-10-29 22:23:06 +02:00
ctx := cmd.Context()
log.Printf("Building image: %s\n", imageTag)
2022-10-29 18:00:16 +02:00
2022-10-29 22:23:06 +02:00
client, err := internal.New(ctx)
if err != nil {
return err
2022-10-29 19:06:50 +02:00
}
2022-10-29 22:23:06 +02:00
defer client.CleanUp()
2022-10-29 19:06:50 +02:00
2022-10-29 22:23:06 +02:00
return tasks.Build(client, imageTag)
2022-10-29 18:00:16 +02:00
},
}
cmd.PersistentFlags().StringVar(&imageTag, "image-tag", "", "the url for which to tag the docker image, defaults to private url, with repo as image name")
2022-10-29 22:23:06 +02:00
cmd.MarkPersistentFlagRequired("image-tag")
2022-10-29 18:15:55 +02:00
2022-10-29 18:00:16 +02:00
return cmd
}