From e40d632c67ca1a3e6aff16ea3c49674a6bd1e509 Mon Sep 17 00:00:00 2001 From: Hanshal Mehta <122217807+hanshal101@users.noreply.github.com> Date: Thu, 4 Jul 2024 02:26:13 +0530 Subject: [PATCH 01/11] feat: add --check flag to the update command Signed-off-by: hanshal101 <82961842+hanshal101@users.noreply.github.com> --- cmd/update/update.go | 78 +++++++++++++++++++++++++++++++++----------- 1 file changed, 59 insertions(+), 19 deletions(-) diff --git a/cmd/update/update.go b/cmd/update/update.go index 3e8766ec..e05ff452 100644 --- a/cmd/update/update.go +++ b/cmd/update/update.go @@ -19,30 +19,33 @@ import ( "github.com/buildsafedev/bsf/pkg/update" ) +var updateCmdOptions struct { + check bool +} + // UpdateCmd represents the update command var UpdateCmd = &cobra.Command{ Use: "update", - Short: "updates dependencies to highest version based on constraints", + Short: "Updates dependencies to the highest version based on constraints", Long: `Updates can be done for development and runtime dependencies based on constraints. Following constraints are supported: ~ : latest patch version ^ : latest minor version Currently, only packages following semver versioning are supported. - - `, +The --check flag allows you to check for available updates without applying them. If updates are available, the command exits with status code 1.`, Run: func(cmd *cobra.Command, args []string) { - fmt.Println(styles.TextStyle.Render("Updating...")) + fmt.Println(styles.TextStyle.Render("Checking for updates...")) conf, err := configure.PreCheckConf() if err != nil { - fmt.Println(styles.ErrorStyle.Render("error:", err.Error())) + fmt.Println(styles.ErrorStyle.Render("Error:", err.Error())) os.Exit(1) } data, err := os.ReadFile("bsf.hcl") if err != nil { - fmt.Println(styles.ErrorStyle.Render("error: ", err.Error())) + fmt.Println(styles.ErrorStyle.Render("Error:", err.Error())) os.Exit(1) } @@ -55,7 +58,7 @@ var UpdateCmd = &cobra.Command{ sc, err := search.NewClientWithAddr(conf.BuildSafeAPI, conf.BuildSafeAPITLS) if err != nil { - fmt.Println(styles.ErrorStyle.Render("error: ", err.Error())) + fmt.Println(styles.ErrorStyle.Render("Error:", err.Error())) os.Exit(1) } @@ -70,35 +73,70 @@ var UpdateCmd = &cobra.Command{ Runtime: runtimeVersions, } + if updateCmdOptions.check { + if !compareVersions(hconf.Packages.Development, devVersions) || !compareVersions(hconf.Packages.Runtime, runtimeVersions) { + fmt.Println(styles.WarnStyle.Render("Updates are available")) + os.Exit(1) + } else { + fmt.Println(styles.SucessStyle.Render("No updates available")) + os.Exit(0) + } + } + fh, err := hcl2nix.NewFileHandlers(true) if err != nil { - fmt.Println(styles.ErrorStyle.Render("Error creating file handlers: %s", err.Error())) + fmt.Println(styles.ErrorStyle.Render("Error creating file handlers:", err.Error())) os.Exit(1) } - // changing file handler to allow writes + // Changing file handler to allow writes fh.ModFile, err = os.Create("bsf.hcl") if err != nil { - fmt.Println(styles.ErrorStyle.Render("Error creating bsf.hcl: %s", err.Error())) + fmt.Println(styles.ErrorStyle.Render("Error creating bsf.hcl:", err.Error())) os.Exit(1) } err = hcl2nix.SetPackages(data, newPackages, fh.ModFile) if err != nil { - fmt.Println(styles.ErrorStyle.Render("Error updating bsf.hcl: %s", err.Error())) + fmt.Println(styles.ErrorStyle.Render("Error updating bsf.hcl:", err.Error())) os.Exit(1) } err = generate.Generate(fh, sc) if err != nil { - fmt.Println(styles.ErrorStyle.Render("Error generating files: %s", err.Error())) + fmt.Println(styles.ErrorStyle.Render("Error generating files:", err.Error())) os.Exit(1) } - fmt.Println(styles.SucessStyle.Render("Updated ran successfully")) - + fmt.Println(styles.SucessStyle.Render("Update ran successfully")) }, } +// This function compares the devVersions and the runtimeVersions +func compareVersions(a, b []string) bool { + if len(a) != len(b) { + return false + } + + counts := make(map[string]int) + for _, item := range a { + counts[item]++ + } + for _, item := range b { + if counts[item] == 0 { + return false + } + counts[item]-- + } + + for _, count := range counts { + if count != 0 { + return false + } + } + + return true +} + func parsePackagesForUpdates(versionMap map[string]*buildsafev1.FetchPackagesResponse) []string { newVersions := make([]string, 0, len(versionMap)) @@ -106,7 +144,7 @@ func parsePackagesForUpdates(versionMap map[string]*buildsafev1.FetchPackagesRes name, version := update.ParsePackage(k) if !semver.IsValid("v" + version) { - fmt.Println(styles.WarnStyle.Render("warning:", "skipping ", k, " as only semver updates are supported currently")) + fmt.Println(styles.WarnStyle.Render("Warning: skipping", k, "as only semver updates are supported currently")) newVersions = append(newVersions, k) continue } @@ -129,9 +167,7 @@ func parsePackagesForUpdates(versionMap map[string]*buildsafev1.FetchPackagesRes case update.UpdateTypePinned: newVersions = append(newVersions, k) continue - } - } return newVersions } @@ -143,7 +179,7 @@ func fetchPackageVersions(packages []string, sc buildsafev1.SearchServiceClient) for _, pkg := range packages { name, version := update.ParsePackage(pkg) if name == "" || version == "" { - fmt.Println(styles.ErrorStyle.Render("error:", "invalid package name or version")) + fmt.Println(styles.ErrorStyle.Render("Error:", "invalid package name or version")) continue } @@ -154,7 +190,7 @@ func fetchPackageVersions(packages []string, sc buildsafev1.SearchServiceClient) Name: name, }) if err != nil { - fmt.Println(styles.ErrorStyle.Render("error finding ", name, ":", err.Error())) + fmt.Println(styles.ErrorStyle.Render("Error finding", name+":", err.Error())) return } @@ -165,3 +201,7 @@ func fetchPackageVersions(packages []string, sc buildsafev1.SearchServiceClient) return versionsMap } + +func init() { + UpdateCmd.PersistentFlags().BoolVarP(&updateCmdOptions.check, "check", "c", false, "Check for updates without applying them") +} From eb3ae6525cebe11b3446493b7ba7851f1701b7a9 Mon Sep 17 00:00:00 2001 From: Hanshal Mehta <122217807+hanshal101@users.noreply.github.com> Date: Thu, 4 Jul 2024 02:32:56 +0530 Subject: [PATCH 02/11] feat: add --check flag to the update command Signed-off-by: hanshal101 <82961842+hanshal101@users.noreply.github.com> --- cmd/update/update.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/cmd/update/update.go b/cmd/update/update.go index e05ff452..9d640cf2 100644 --- a/cmd/update/update.go +++ b/cmd/update/update.go @@ -26,26 +26,26 @@ var updateCmdOptions struct { // UpdateCmd represents the update command var UpdateCmd = &cobra.Command{ Use: "update", - Short: "Updates dependencies to the highest version based on constraints", + Short: "updates dependencies to highest version based on constraints", Long: `Updates can be done for development and runtime dependencies based on constraints. Following constraints are supported: ~ : latest patch version ^ : latest minor version Currently, only packages following semver versioning are supported. -The --check flag allows you to check for available updates without applying them. If updates are available, the command exits with status code 1.`, + `, Run: func(cmd *cobra.Command, args []string) { - fmt.Println(styles.TextStyle.Render("Checking for updates...")) + fmt.Println(styles.TextStyle.Render("Updating...")) conf, err := configure.PreCheckConf() if err != nil { - fmt.Println(styles.ErrorStyle.Render("Error:", err.Error())) + fmt.Println(styles.ErrorStyle.Render("error:", err.Error())) os.Exit(1) } data, err := os.ReadFile("bsf.hcl") if err != nil { - fmt.Println(styles.ErrorStyle.Render("Error:", err.Error())) + fmt.Println(styles.ErrorStyle.Render("error:", err.Error())) os.Exit(1) } @@ -58,7 +58,7 @@ The --check flag allows you to check for available updates without applying them sc, err := search.NewClientWithAddr(conf.BuildSafeAPI, conf.BuildSafeAPITLS) if err != nil { - fmt.Println(styles.ErrorStyle.Render("Error:", err.Error())) + fmt.Println(styles.ErrorStyle.Render("error:", err.Error())) os.Exit(1) } @@ -85,29 +85,29 @@ The --check flag allows you to check for available updates without applying them fh, err := hcl2nix.NewFileHandlers(true) if err != nil { - fmt.Println(styles.ErrorStyle.Render("Error creating file handlers:", err.Error())) + fmt.Println(styles.ErrorStyle.Render("Error creating file handlers: %s", err.Error())) os.Exit(1) } - // Changing file handler to allow writes + // changing file handler to allow writes fh.ModFile, err = os.Create("bsf.hcl") if err != nil { - fmt.Println(styles.ErrorStyle.Render("Error creating bsf.hcl:", err.Error())) + fmt.Println(styles.ErrorStyle.Render("Error creating bsf.hcl: %s", err.Error())) os.Exit(1) } err = hcl2nix.SetPackages(data, newPackages, fh.ModFile) if err != nil { - fmt.Println(styles.ErrorStyle.Render("Error updating bsf.hcl:", err.Error())) + fmt.Println(styles.ErrorStyle.Render("Error updating bsf.hcl: %s", err.Error())) os.Exit(1) } err = generate.Generate(fh, sc) if err != nil { - fmt.Println(styles.ErrorStyle.Render("Error generating files:", err.Error())) + fmt.Println(styles.ErrorStyle.Render("Error generating files: %s", err.Error())) os.Exit(1) } - fmt.Println(styles.SucessStyle.Render("Update ran successfully")) + fmt.Println(styles.SucessStyle.Render("Updated ran successfully")) }, } From 2ffee94be5b145b17d40885739cab176625ff894 Mon Sep 17 00:00:00 2001 From: Hanshal Mehta <122217807+hanshal101@users.noreply.github.com> Date: Thu, 4 Jul 2024 02:35:25 +0530 Subject: [PATCH 03/11] feat: add --check flag to the update command Signed-off-by: hanshal101 <82961842+hanshal101@users.noreply.github.com> --- cmd/update/update.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/update/update.go b/cmd/update/update.go index 9d640cf2..5b05be17 100644 --- a/cmd/update/update.go +++ b/cmd/update/update.go @@ -144,7 +144,7 @@ func parsePackagesForUpdates(versionMap map[string]*buildsafev1.FetchPackagesRes name, version := update.ParsePackage(k) if !semver.IsValid("v" + version) { - fmt.Println(styles.WarnStyle.Render("Warning: skipping", k, "as only semver updates are supported currently")) + fmt.Println(styles.WarnStyle.Render("warning:", "skipping ", k, " as only semver updates are supported currently")) newVersions = append(newVersions, k) continue } @@ -179,7 +179,7 @@ func fetchPackageVersions(packages []string, sc buildsafev1.SearchServiceClient) for _, pkg := range packages { name, version := update.ParsePackage(pkg) if name == "" || version == "" { - fmt.Println(styles.ErrorStyle.Render("Error:", "invalid package name or version")) + fmt.Println(styles.ErrorStyle.Render("error:", "invalid package name or version")) continue } @@ -190,7 +190,7 @@ func fetchPackageVersions(packages []string, sc buildsafev1.SearchServiceClient) Name: name, }) if err != nil { - fmt.Println(styles.ErrorStyle.Render("Error finding", name+":", err.Error())) + fmt.Println(styles.ErrorStyle.Render("error finding ", name, ":", err.Error())) return } From 5a5fb5d81a12a838e49b05cd3d412e6ac902492f Mon Sep 17 00:00:00 2001 From: Hanshal Mehta <122217807+hanshal101@users.noreply.github.com> Date: Thu, 4 Jul 2024 03:36:30 +0530 Subject: [PATCH 04/11] feat: add --check flag to the update command Signed-off-by: hanshal101 <82961842+hanshal101@users.noreply.github.com> --- CONTRIBUTORS.md | 3 ++- cmd/update/update.go | 28 +--------------------------- pkg/update/update.go | 26 ++++++++++++++++++++++++++ pkg/update/update_test.go | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 28 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index f365d5fc..79052528 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -11,4 +11,5 @@ We contributors to BuildSafe: * House (@dr-housemd) * Rakshit(@rakshitgondwal) * Praful(@Horiodino) -* Sanyam(@sanyamjain04) \ No newline at end of file +* Sanyam(@sanyamjain04) +* Hanshal(@hanshal101) \ No newline at end of file diff --git a/cmd/update/update.go b/cmd/update/update.go index 5b05be17..f2121aed 100644 --- a/cmd/update/update.go +++ b/cmd/update/update.go @@ -74,7 +74,7 @@ var UpdateCmd = &cobra.Command{ } if updateCmdOptions.check { - if !compareVersions(hconf.Packages.Development, devVersions) || !compareVersions(hconf.Packages.Runtime, runtimeVersions) { + if !update.CompareVersions(hconf.Packages.Development, devVersions) || !update.CompareVersions(hconf.Packages.Runtime, runtimeVersions) { fmt.Println(styles.WarnStyle.Render("Updates are available")) os.Exit(1) } else { @@ -111,32 +111,6 @@ var UpdateCmd = &cobra.Command{ }, } -// This function compares the devVersions and the runtimeVersions -func compareVersions(a, b []string) bool { - if len(a) != len(b) { - return false - } - - counts := make(map[string]int) - for _, item := range a { - counts[item]++ - } - for _, item := range b { - if counts[item] == 0 { - return false - } - counts[item]-- - } - - for _, count := range counts { - if count != 0 { - return false - } - } - - return true -} - func parsePackagesForUpdates(versionMap map[string]*buildsafev1.FetchPackagesResponse) []string { newVersions := make([]string, 0, len(versionMap)) diff --git a/pkg/update/update.go b/pkg/update/update.go index 52492c90..4d5cb87f 100644 --- a/pkg/update/update.go +++ b/pkg/update/update.go @@ -101,3 +101,29 @@ func TrimVersionInfo(pkg string) (string, string) { return name, version } + +// This function compares the devVersions and the runtimeVersions +func CompareVersions(a, b []string) bool { + if len(a) != len(b) { + return false + } + + counts := make(map[string]int) + for _, item := range a { + counts[item]++ + } + for _, item := range b { + if counts[item] == 0 { + return false + } + counts[item]-- + } + + for _, count := range counts { + if count != 0 { + return false + } + } + + return true +} diff --git a/pkg/update/update_test.go b/pkg/update/update_test.go index ea610c09..4c481a23 100644 --- a/pkg/update/update_test.go +++ b/pkg/update/update_test.go @@ -198,3 +198,39 @@ func TestParseUpdateType(t *testing.T) { }) } } + +func TestCompareVersions(t *testing.T) { + tests := []struct { + name string + a []string + b []string + want bool + }{ + { + name: "Test Case 1 - Equal slices", + a: []string{"v1.0.0", "v1.1.0", "v1.2.0"}, + b: []string{"v1.2.0", "v1.1.0", "v1.0.0"}, + want: true, + }, + { + name: "Test Case 2 - Different slices", + a: []string{"v1.0.0", "v1.1.0", "v1.2.0"}, + b: []string{"v1.2.0", "v1.1.0", "v1.3.0"}, + want: false, + }, + { + name: "Test Case 3 - Different lengths", + a: []string{"v1.0.0", "v1.1.0"}, + b: []string{"v1.2.0", "v1.1.0", "v1.0.0"}, + want: false, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CompareVersions(tt.a, tt.b); got != tt.want { + t.Errorf("CompareVersions() = %v, want %v", got, tt.want) + } + }) + } +} From 7401cdf346c4a5c7b1d903b16a6ff63d23598279 Mon Sep 17 00:00:00 2001 From: Hanshal Mehta <122217807+hanshal101@users.noreply.github.com> Date: Thu, 4 Jul 2024 03:42:25 +0530 Subject: [PATCH 05/11] feat: add --check flag to the update command Signed-off-by: hanshal101 <82961842+hanshal101@users.noreply.github.com> --- pkg/update/update_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/update/update_test.go b/pkg/update/update_test.go index 4c481a23..d6689a72 100644 --- a/pkg/update/update_test.go +++ b/pkg/update/update_test.go @@ -208,20 +208,20 @@ func TestCompareVersions(t *testing.T) { }{ { name: "Test Case 1 - Equal slices", - a: []string{"v1.0.0", "v1.1.0", "v1.2.0"}, - b: []string{"v1.2.0", "v1.1.0", "v1.0.0"}, + a: []string{"pkg1@~v1.0.0", "pkg2@~v1.1.0", "pkg3@~v1.2.0"}, + b: []string{"pkg3@~v1.2.0", "pkg2@~v1.1.0", "pkg1@~v1.0.0"}, want: true, }, { name: "Test Case 2 - Different slices", - a: []string{"v1.0.0", "v1.1.0", "v1.2.0"}, - b: []string{"v1.2.0", "v1.1.0", "v1.3.0"}, + a: []string{"pkg1@~v1.0.0", "pkg2@~v1.1.0", "pkg3@~v1.2.0"}, + b: []string{"pkg1@~v1.2.0", "pkg2@~v1.1.0", "pkg3@~v1.3.0"}, want: false, }, { name: "Test Case 3 - Different lengths", - a: []string{"v1.0.0", "v1.1.0"}, - b: []string{"v1.2.0", "v1.1.0", "v1.0.0"}, + a: []string{"pkg1@~v1.0.0", "pkg2@~v1.1.0"}, + b: []string{"pkg2@~v1.2.0", "pkg1@~v1.1.0", "pkg3@~v1.0.0"}, want: false, }, } From 884577d68520a91bc5d1bec7fcbc1c0720484754 Mon Sep 17 00:00:00 2001 From: Hanshal Mehta <122217807+hanshal101@users.noreply.github.com> Date: Thu, 4 Jul 2024 03:48:06 +0530 Subject: [PATCH 06/11] feat: add --check flag to the update command Signed-off-by: hanshal101 <82961842+hanshal101@users.noreply.github.com> --- cmd/update/update.go | 2 +- pkg/update/update.go | 2 +- pkg/update/update_test.go | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/update/update.go b/cmd/update/update.go index f2121aed..a4ac0852 100644 --- a/cmd/update/update.go +++ b/cmd/update/update.go @@ -74,7 +74,7 @@ var UpdateCmd = &cobra.Command{ } if updateCmdOptions.check { - if !update.CompareVersions(hconf.Packages.Development, devVersions) || !update.CompareVersions(hconf.Packages.Runtime, runtimeVersions) { + if !update.ComparePackages(hconf.Packages.Development, devVersions) || !update.ComparePackages(hconf.Packages.Runtime, runtimeVersions) { fmt.Println(styles.WarnStyle.Render("Updates are available")) os.Exit(1) } else { diff --git a/pkg/update/update.go b/pkg/update/update.go index 4d5cb87f..fffe7aad 100644 --- a/pkg/update/update.go +++ b/pkg/update/update.go @@ -103,7 +103,7 @@ func TrimVersionInfo(pkg string) (string, string) { } // This function compares the devVersions and the runtimeVersions -func CompareVersions(a, b []string) bool { +func ComparePackages(a, b []string) bool { if len(a) != len(b) { return false } diff --git a/pkg/update/update_test.go b/pkg/update/update_test.go index d6689a72..e8df91c7 100644 --- a/pkg/update/update_test.go +++ b/pkg/update/update_test.go @@ -199,7 +199,7 @@ func TestParseUpdateType(t *testing.T) { } } -func TestCompareVersions(t *testing.T) { +func TestComparePackages(t *testing.T) { tests := []struct { name string a []string @@ -228,7 +228,7 @@ func TestCompareVersions(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := CompareVersions(tt.a, tt.b); got != tt.want { + if got := ComparePackages(tt.a, tt.b); got != tt.want { t.Errorf("CompareVersions() = %v, want %v", got, tt.want) } }) From e8824a66b905e120f4b9db025d6f12a10bfad304 Mon Sep 17 00:00:00 2001 From: Hanshal Mehta <122217807+hanshal101@users.noreply.github.com> Date: Thu, 4 Jul 2024 03:49:16 +0530 Subject: [PATCH 07/11] feat: add --check flag to the update command Signed-off-by: hanshal101 <82961842+hanshal101@users.noreply.github.com> --- pkg/update/update.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/update/update.go b/pkg/update/update.go index fffe7aad..d198bd83 100644 --- a/pkg/update/update.go +++ b/pkg/update/update.go @@ -102,7 +102,7 @@ func TrimVersionInfo(pkg string) (string, string) { return name, version } -// This function compares the devVersions and the runtimeVersions +// ComparePackages compares the devVersions and the runtimeVersions func ComparePackages(a, b []string) bool { if len(a) != len(b) { return false From f9d61dfa0fae385f2ae52c5e2762c3be64d4bf6d Mon Sep 17 00:00:00 2001 From: Hanshal Mehta <122217807+hanshal101@users.noreply.github.com> Date: Thu, 4 Jul 2024 03:54:21 +0530 Subject: [PATCH 08/11] feat: add --check flag to the update command Signed-off-by: hanshal101 <82961842+hanshal101@users.noreply.github.com> --- cmd/update/update.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cmd/update/update.go b/cmd/update/update.go index a4ac0852..4cc67b5c 100644 --- a/cmd/update/update.go +++ b/cmd/update/update.go @@ -77,10 +77,9 @@ var UpdateCmd = &cobra.Command{ if !update.ComparePackages(hconf.Packages.Development, devVersions) || !update.ComparePackages(hconf.Packages.Runtime, runtimeVersions) { fmt.Println(styles.WarnStyle.Render("Updates are available")) os.Exit(1) - } else { - fmt.Println(styles.SucessStyle.Render("No updates available")) - os.Exit(0) } + fmt.Println(styles.SucessStyle.Render("No updates available")) + os.Exit(0) } fh, err := hcl2nix.NewFileHandlers(true) From 65f0b7cffddc7551fc3e44df839bee603fea7f57 Mon Sep 17 00:00:00 2001 From: Hanshal Mehta <122217807+hanshal101@users.noreply.github.com> Date: Thu, 4 Jul 2024 03:58:35 +0530 Subject: [PATCH 09/11] feat: add --check flag to the update command Signed-off-by: hanshal101 <82961842+hanshal101@users.noreply.github.com> --- pkg/update/update.go | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/pkg/update/update.go b/pkg/update/update.go index d198bd83..f2cf71d2 100644 --- a/pkg/update/update.go +++ b/pkg/update/update.go @@ -108,19 +108,12 @@ func ComparePackages(a, b []string) bool { return false } - counts := make(map[string]int) + counts := make(map[string]bool) for _, item := range a { - counts[item]++ + counts[item] = true } for _, item := range b { - if counts[item] == 0 { - return false - } - counts[item]-- - } - - for _, count := range counts { - if count != 0 { + if counts[item] { return false } } From 6c048472a14538826c312403e5fa595a5e195101 Mon Sep 17 00:00:00 2001 From: Hanshal Mehta <122217807+hanshal101@users.noreply.github.com> Date: Thu, 4 Jul 2024 04:02:27 +0530 Subject: [PATCH 10/11] feat: add --check flag to the update command Signed-off-by: hanshal101 <82961842+hanshal101@users.noreply.github.com> --- cmd/update/update.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/cmd/update/update.go b/cmd/update/update.go index 4cc67b5c..b28366c0 100644 --- a/cmd/update/update.go +++ b/cmd/update/update.go @@ -19,9 +19,7 @@ import ( "github.com/buildsafedev/bsf/pkg/update" ) -var updateCmdOptions struct { - check bool -} +var check bool // UpdateCmd represents the update command var UpdateCmd = &cobra.Command{ @@ -73,7 +71,7 @@ var UpdateCmd = &cobra.Command{ Runtime: runtimeVersions, } - if updateCmdOptions.check { + if check { if !update.ComparePackages(hconf.Packages.Development, devVersions) || !update.ComparePackages(hconf.Packages.Runtime, runtimeVersions) { fmt.Println(styles.WarnStyle.Render("Updates are available")) os.Exit(1) @@ -176,5 +174,5 @@ func fetchPackageVersions(packages []string, sc buildsafev1.SearchServiceClient) } func init() { - UpdateCmd.PersistentFlags().BoolVarP(&updateCmdOptions.check, "check", "c", false, "Check for updates without applying them") + UpdateCmd.PersistentFlags().BoolVarP(&check, "check", "c", false, "Check for updates without applying them") } From 3b32477a18555df91d8b94b76427380d9ad3ef27 Mon Sep 17 00:00:00 2001 From: Hanshal Mehta <122217807+hanshal101@users.noreply.github.com> Date: Thu, 4 Jul 2024 04:05:14 +0530 Subject: [PATCH 11/11] feat: add --check flag to the update command Signed-off-by: hanshal101 <82961842+hanshal101@users.noreply.github.com> --- pkg/update/update.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/update/update.go b/pkg/update/update.go index f2cf71d2..dfb4f500 100644 --- a/pkg/update/update.go +++ b/pkg/update/update.go @@ -113,7 +113,7 @@ func ComparePackages(a, b []string) bool { counts[item] = true } for _, item := range b { - if counts[item] { + if !counts[item] { return false } }