From 251bcb2f087e7746011cb8a8170035fbc5828a52 Mon Sep 17 00:00:00 2001 From: Abinand P Date: Sat, 5 Oct 2024 23:56:17 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=A8=20=20interactive=20create=20templa?= =?UTF-8?q?te=20cyctl=20(#611)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added the package promptui and added the interactive mode where it requests the repo, path and version one after another Signed-off-by: Abinand P * go mod tidy --------- Signed-off-by: Abinand P Co-authored-by: petar-cvit --- cyctl/go.mod | 2 ++ cyctl/go.sum | 9 +++++++ cyctl/internal/create/template_store.go | 34 +++++++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/cyctl/go.mod b/cyctl/go.mod index 2f642d74..6ad23fe4 100644 --- a/cyctl/go.mod +++ b/cyctl/go.mod @@ -6,6 +6,7 @@ toolchain go1.22.2 require ( github.com/cyclops-ui/cyclops/cyclops-ctrl v0.0.0-20240917130002-9f787d2ad567 + github.com/manifoldco/promptui v0.9.0 github.com/spf13/cobra v1.8.0 k8s.io/api v0.30.1 k8s.io/apiextensions-apiserver v0.30.1 @@ -17,6 +18,7 @@ require ( require ( github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/emicklei/go-restful/v3 v3.11.0 // indirect github.com/evanphx/json-patch/v5 v5.9.0 // indirect diff --git a/cyctl/go.sum b/cyctl/go.sum index d30e173e..945b61eb 100644 --- a/cyctl/go.sum +++ b/cyctl/go.sum @@ -4,6 +4,12 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE= +github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/cyclops-ui/cyclops/cyclops-ctrl v0.0.0-20240917130002-9f787d2ad567 h1:LtIXcvDlA93iNXNTpxW+bWlTzfXZYoinRwTFUr9IlVA= @@ -73,6 +79,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= +github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA= +github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg= github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= github.com/moby/spdystream v0.2.0 h1:cjW1zVyyoiM0T7b6UoySUFqzXMoqRckQtXwGPiBhOM8= @@ -146,6 +154,7 @@ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/cyctl/internal/create/template_store.go b/cyctl/internal/create/template_store.go index 76ac0da7..efffa3aa 100644 --- a/cyctl/internal/create/template_store.go +++ b/cyctl/internal/create/template_store.go @@ -8,6 +8,7 @@ import ( "github.com/cyclops-ui/cyclops/cyclops-ctrl/api/v1alpha1" "github.com/cyclops-ui/cyclops/cyclops-ctrl/api/v1alpha1/client" "github.com/cyclops-ui/cycops-cyctl/internal/kubeconfig" + "github.com/manifoldco/promptui" "github.com/spf13/cobra" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/yaml" @@ -30,6 +31,39 @@ var ( ) func createTemplate(clientset *client.CyclopsV1Alpha1Client, templateName, path, version, namespace, outputFormat string) { + // Check wheter the flags --repo --path --version are defined + if path == "" && version == "" && repo == "" { + RepoPrompt := promptui.Prompt{ + Label: "Repo", + } + repoValue, err := RepoPrompt.Run() + if err != nil { + fmt.Printf("Prompt failed %v", err) + return + } + repo = repoValue + + PathPrompt := promptui.Prompt{ + Label: "Path", + } + pathValue, err := PathPrompt.Run() + if err != nil { + fmt.Printf("Prompt failed %v", err) + return + } + path = pathValue + + VersionPrompt := promptui.Prompt{ + Label: "Version", + } + versionValue, err := VersionPrompt.Run() + if err != nil { + fmt.Printf("Prompt failed %v", err) + return + } + version = versionValue + } + // Define a new TemplateStore object newTemplate := v1alpha1.TemplateStore{ TypeMeta: v1.TypeMeta{