Skip to content

Commit

Permalink
tested the ignoreDuplicates flag and refactored the code a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
aminalali8 committed May 20, 2024
1 parent 0f88508 commit a495485
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions cmd/variable/action/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package action

import (
"errors"
"fmt"

Check failure on line 5 in cmd/variable/action/import.go

View workflow job for this annotation

GitHub Actions / audit

"fmt" imported and not used

"bunnyshell.com/cli/pkg/api/variable"
"bunnyshell.com/cli/pkg/config"
Expand Down Expand Up @@ -59,7 +60,7 @@ func init() {
for key, value := range data.Vars {
err := createEnvVar(cmd, key, value, false)
if err != nil {
if ignoreDuplicates && err.Error() == "An Environment Variable with this name already exists in this environment." {
if ignoreDuplicates && err.Error() == "An error occurred: name: An Environment Variable with this name already exists in this environment." {
continue
} else {
return lib.FormatCommandError(cmd, err)
Expand All @@ -72,7 +73,7 @@ func init() {
for key, value := range data.Secrets {
err := createEnvVar(cmd, key, value, true)
if err != nil {
if ignoreDuplicates && err.Error() == "An Environment Variable with this name already exists in this environment." {
if ignoreDuplicates && err.Error() == "An error occurred: name: An Environment Variable with this name already exists in this environment." {
continue
} else {
return lib.FormatCommandError(cmd, err)
Expand All @@ -89,7 +90,7 @@ func init() {

flags.StringVar(&varFile, "vars-file", varFile, "File to import variables from")
flags.StringVar(&secretFile, "secrets-file", secretFile, "File to import secrets from")
flags.BoolVarP(&ignoreDuplicates, "ignore-duplicates", "ign-dp", false, "Skip variables that already exist in the environment")
flags.BoolVarP(&ignoreDuplicates, "ignore-duplicates", "", false, "Skip variables that already exist in the environment")

flags.AddFlag(options.Environment.AddFlagWithExtraHelp(
"environment",
Expand Down Expand Up @@ -140,4 +141,4 @@ func createEnvVar(cmd *cobra.Command, name string, value string, isSecret bool)
}

return nil
}
}

0 comments on commit a495485

Please sign in to comment.