Skip to content

Commit

Permalink
fix: updated the suggested modfications from the review
Browse files Browse the repository at this point in the history
  • Loading branch information
Abiji-2020 committed Oct 6, 2024
1 parent 96b15c1 commit 9c72bac
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions cyctl/internal/update/template_store.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package update
package update

import (
"fmt"
"log"

"github.com/cyclops-ui/cyclops/cyclops-ctrl/api/v1alpha1/client"
"github.com/cyclops-ui/cycops-cyctl/internal/kubeconfig"
"github.com/spf13/cobra"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"

)

var (
Expand All @@ -18,18 +18,18 @@ var (
)

var (
repo string
path string
icon string
version string
repo string
path string
icon string
version string
)

// updates he given template from cyclops API
func updateTemplate(clientset *client.CyclopsV1Alpha1Client, templateName, path, version, repo, icon string) {
// Fetch the existing template store
template, err := clientset.TemplateStore("cyclops").Get(templateName)
if err != nil {
fmt.Println("Failed to fetchtemplate store ", err)
log.Fatal("Failed to fetch template store:", err.Error())
return
}

Expand All @@ -51,37 +51,34 @@ func updateTemplate(clientset *client.CyclopsV1Alpha1Client, templateName, path,
}
template.TypeMeta = v1.TypeMeta{
APIVersion: "cyclops-ui.com/v1alpha1",
Kind: "TemplateStore",

Kind: "TemplateStore",
}

// Update the template store in the cluster
_ , err = clientset.TemplateStore("cyclops").Update(template)
_, err = clientset.TemplateStore("cyclops").Update(template)
if err != nil {
fmt.Println("Failed to update template store ", err)
return
return
}

fmt.Printf("successfully updated %v", templateName)
}

var (
UpdateTemplateStoreCMD = &cobra.Command{
Use: "template",
Short: " updates template values; takes template name as an argument with flags for updation",
Long: " updates template values; takes template name as an argument with flags --path=<path> --repo=<repo> --version=<version> --icon=<icon> ",
Use: "template",
Short: " updates template values; takes template name as argument and updates values provided by flags",
Long: " updates template values; takes template name as argument with flags --path=<path> --repo=<repo> --version=<version> --icon=<icon> ",
Example: updateTemplateStoreExample,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string){
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
templateName := args[0]

if repo == "" && path == "" && version == "" && icon == "" {
fmt.Println("Error: At least one of --repo, --path, --version, or --icon must be provided.")
cmd.Usage() // Print usage information
return
log.Fatal("Error: At least on of --repo, --path, --version, or --icon must be provided.")
}

updateTemplate(kubeconfig.Moduleset, templateName, path, version, repo, icon )
updateTemplate(kubeconfig.Moduleset, templateName, path, version, repo, icon)
},
}
)
Expand Down

0 comments on commit 9c72bac

Please sign in to comment.