@@ -167,6 +167,25 @@ func stageChanges() {
167167// It only changes version number in package.json by default.
168168// `files` is a comma seperated string of other files to change version in.
169169func updateVersionNumbers (level string , files string ) {
170+ // Make a map of levels to their respective numbers of the version number
171+ var table = map [string ]int {
172+ "major" : 0 ,
173+ "minor" : 1 ,
174+ "patch" : 2 ,
175+ }
176+
177+ // Check if level is valid
178+ var err error = fmt .Errorf ("Invalid level. Use one of the following: major, minor, patch." )
179+ for key := range table {
180+ if key == level {
181+ err = nil
182+ }
183+ }
184+ check (err )
185+
186+ // Get the index of the version number to increment
187+ index := table [level ]
188+
170189 // Read the package.json file
171190 packageJSONBytes , err := os .ReadFile ("package.json" )
172191 check (err )
@@ -180,14 +199,6 @@ func updateVersionNumbers(level string, files string) {
180199 newVersion := strings .Split (packageJSONMap ["version" ].(string ), "." )
181200 var num int
182201
183- // Get the index of the version number to increment
184- var table = map [string ]int {
185- "major" : 0 ,
186- "minor" : 1 ,
187- "patch" : 2 ,
188- }
189- index := table [level ]
190-
191202 // Update the version number
192203 num , err = strconv .Atoi (newVersion [index ])
193204 check (err )
@@ -290,12 +301,6 @@ func main() {
290301 },
291302 Action : func (c * cli.Context ) (err error ) {
292303 level := c .Args ().First ()
293- // Check if level is valid
294- if level != "major" && level != "minor" && level != "patch" {
295- fmt .Println ("Invalid level. Use one of the following: major, minor, patch." )
296- return
297- }
298-
299304 updateVersionNumbers (level , files )
300305 return
301306 },
0 commit comments