From 45ca537f6ddaa52e778315c74c7e4a0cb1dee057 Mon Sep 17 00:00:00 2001 From: kjuulh Date: Sat, 29 Oct 2022 18:15:55 +0200 Subject: [PATCH] update as library --- main.go | 16 ---------------- cmd/build.go => pkg/cli/cli.go | 7 +++++-- pkg/tasks/build.go | 10 ++++++++++ 3 files changed, 15 insertions(+), 18 deletions(-) delete mode 100644 main.go rename cmd/build.go => pkg/cli/cli.go (75%) create mode 100644 pkg/tasks/build.go diff --git a/main.go b/main.go deleted file mode 100644 index cdb8109..0000000 --- a/main.go +++ /dev/null @@ -1,16 +0,0 @@ -package daggergo - -import ( - "git.front.kjuulh.io/kjuulh/dagger-go/cmd" - "github.com/spf13/cobra" -) - -func CreateCmd() *cobra.Command { - cobracmd := &cobra.Command{ - Use: "dagger-go", - } - - cobracmd.AddCommand(cmd.Build()) - - return cobracmd -} diff --git a/cmd/build.go b/pkg/cli/cli.go similarity index 75% rename from cmd/build.go rename to pkg/cli/cli.go index ceb8129..2cff8a1 100644 --- a/cmd/build.go +++ b/pkg/cli/cli.go @@ -1,12 +1,13 @@ package cmd import ( + "context" "log" "github.com/spf13/cobra" ) -func Build() *cobra.Command { +func Build(requirementsf func(*cobra.Command), buildf func(ctx context.Context) error) *cobra.Command { var ( imageTag string ) @@ -22,11 +23,13 @@ func Build() *cobra.Command { log.Printf("Building image: %s\n", imageTag) } - return nil + return buildf(cmd.Context()) }, } cmd.PersistentFlags().StringVar(&imageTag, "image-tag", "", "the url for which to tag the docker image, defaults to private url, with repo as image name") + requirementsf(cmd) + return cmd } diff --git a/pkg/tasks/build.go b/pkg/tasks/build.go new file mode 100644 index 0000000..0cc3a90 --- /dev/null +++ b/pkg/tasks/build.go @@ -0,0 +1,10 @@ +package tasks + +import "log" + +func Build(imageTag string) error { + + log.Printf("building image: %s", imageTag) + + return nil +}