@@ -19,6 +19,7 @@ package update
19
19
import (
20
20
"fmt"
21
21
"net/http"
22
+ "os"
22
23
"os/exec"
23
24
"strings"
24
25
@@ -28,6 +29,9 @@ import (
28
29
29
30
// Validate checks the input info provided for the update and populates the cliVersion
30
31
func (opts * Update ) Validate () error {
32
+ if err := opts .validateEqualVersions (); err != nil {
33
+ return fmt .Errorf ("failed to validate equal versions: %w" , err )
34
+ }
31
35
if err := opts .validateGitRepo (); err != nil {
32
36
return fmt .Errorf ("failed to validate git repository: %w" , err )
33
37
}
@@ -117,3 +121,23 @@ func validateReleaseAvailability(version string) error {
117
121
resp .StatusCode , version )
118
122
}
119
123
}
124
+
125
+ // validateEqualVersions checks if from-version and to-version are the same.
126
+ // If they are equal, logs an appropriate message and exits successfully.
127
+ func (opts * Update ) validateEqualVersions () error {
128
+ if opts .FromVersion == opts .ToVersion {
129
+ // Check if this is the latest version to provide appropriate message
130
+ latestVersion , err := fetchLatestRelease ()
131
+ if err != nil {
132
+ return fmt .Errorf ("failed to fetch latest release for messaging: %w" , err )
133
+ }
134
+
135
+ if opts .ToVersion == latestVersion {
136
+ log .Infof ("Your project already uses the latest version (%s). No action taken." , opts .FromVersion )
137
+ } else {
138
+ log .Infof ("Your project already uses the specified version (%s). No action taken." , opts .FromVersion )
139
+ }
140
+ os .Exit (0 )
141
+ }
142
+ return nil
143
+ }
0 commit comments