Skip to content

Commit 72ba995

Browse files
chore: Use const with values instead of hardcoded strings
1 parent 6a62eb5 commit 72ba995

File tree

1 file changed

+51
-37
lines changed

1 file changed

+51
-37
lines changed

cmd/run.go

Lines changed: 51 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,41 @@ import (
1212
"github.com/spf13/cobra"
1313
)
1414

15+
const (
16+
GitCommitUser = "git-commit-user"
17+
GitCommitEmail = "git-commit-email"
18+
GitPassword = "git-password"
19+
GitBranch = "git-branch"
20+
GitRepoUrl = "git-repo-url"
21+
GitFile = "git-file"
22+
GitDir = "git-dir"
23+
24+
AppName = "app-name"
25+
SshPrivateKey = "ssh-private-key"
26+
DryRun = "dry-run"
27+
LogLevel = "logLevel"
28+
HelmKeyValues = "helm-key-values"
29+
)
30+
1531
var cfg = updater.HelmUpdaterConfig{}
1632

1733
// runCmd represents the run command
1834
var runCmd = &cobra.Command{
1935
Use: "run",
2036
Short: "Runs the helm repo updater",
2137
Run: func(cmd *cobra.Command, args []string) {
22-
gitUser, _ := cmd.Flags().GetString("git-commit-user")
23-
gitEmail, _ := cmd.Flags().GetString("git-commit-email")
24-
gitPass, _ := cmd.Flags().GetString("git-password")
25-
gitBranch, _ := cmd.Flags().GetString("git-branch")
26-
gitRepoURL, _ := cmd.Flags().GetString("git-repo-url")
27-
gitFile, _ := cmd.Flags().GetString("git-file")
28-
gitDir, _ := cmd.Flags().GetString("git-dir")
29-
sshKey, _ := cmd.Flags().GetString("ssh-private-key")
30-
appName, _ := cmd.Flags().GetString("app-name")
31-
logLevel, _ := cmd.Flags().GetString("loglevel")
32-
dryRun, _ := cmd.Flags().GetBool("dry-run")
33-
helmKVs, _ := cmd.Flags().GetStringToString("helm-key-values")
38+
gitUser, _ := cmd.Flags().GetString(GitCommitUser)
39+
gitEmail, _ := cmd.Flags().GetString(GitCommitEmail)
40+
gitPass, _ := cmd.Flags().GetString(GitPassword)
41+
gitBranch, _ := cmd.Flags().GetString(GitBranch)
42+
gitRepoURL, _ := cmd.Flags().GetString(GitRepoUrl)
43+
gitFile, _ := cmd.Flags().GetString(GitFile)
44+
gitDir, _ := cmd.Flags().GetString(GitDir)
45+
sshKey, _ := cmd.Flags().GetString(SshPrivateKey)
46+
appName, _ := cmd.Flags().GetString(AppName)
47+
logLevel, _ := cmd.Flags().GetString(LogLevel)
48+
dryRun, _ := cmd.Flags().GetBool(DryRun)
49+
helmKVs, _ := cmd.Flags().GetStringToString(HelmKeyValues)
3450

3551
if err := log.SetLogLevel(logLevel); err != nil {
3652
fmt.Println(err)
@@ -39,10 +55,10 @@ var runCmd = &cobra.Command{
3955
}
4056

4157
if len(helmKVs) == 0 {
42-
err := cmd.Help()
43-
if err != nil {
58+
if err := cmd.Help(); err != nil {
4459
return
4560
}
61+
4662
os.Exit(1)
4763
}
4864

@@ -86,11 +102,9 @@ var runCmd = &cobra.Command{
86102
GitConf: gitConf,
87103
}
88104

89-
err := runImageUpdater(cfg)
90-
if err != nil {
105+
if err := runImageUpdater(cfg); err != nil {
91106
log.Errorf("Error: %v", err)
92107
}
93-
94108
},
95109
}
96110

@@ -121,25 +135,25 @@ func runImageUpdater(cfg updater.HelmUpdaterConfig) error {
121135
func init() {
122136
rootCmd.AddCommand(runCmd)
123137

124-
runCmd.Flags().String("git-commit-user", "", "Username to use for Git commits")
125-
runCmd.Flags().String("git-commit-email", "", "E-Mail address to use for Git commits")
126-
runCmd.Flags().String("git-password", "", "Password for github user")
127-
runCmd.Flags().String("git-branch", "develop", "branch")
128-
runCmd.Flags().String("git-repo-url", "", "git repo url")
129-
runCmd.Flags().String("git-file", "", "file eg. values.yaml")
130-
runCmd.Flags().String("git-dir", "", "file eg. /production/charts/")
131-
runCmd.Flags().String("app-name", "", "app name")
132-
runCmd.Flags().String("ssh-private-key", "", "ssh private key (only using ")
133-
runCmd.Flags().Bool("dry-run", false, "run in dry-run mode. If set to true, do not perform any changes")
134-
runCmd.Flags().String("loglevel", "info", "set the loglevel to one of trace|debug|info|warn|error")
135-
runCmd.Flags().StringToString("helm-key-values", nil, "helm key-values sets")
136-
137-
_ = runCmd.MarkFlagRequired("git-commit-user")
138-
_ = runCmd.MarkFlagRequired("git-commit-email")
139-
_ = runCmd.MarkFlagRequired("git-repo-url")
140-
_ = runCmd.MarkFlagRequired("git-file")
141-
_ = runCmd.MarkFlagRequired("git-dir")
142-
_ = runCmd.MarkFlagRequired("helm-key-values")
143-
_ = runCmd.MarkFlagRequired("app-name")
138+
runCmd.Flags().String(GitCommitUser, "", "Username to use for Git commits")
139+
runCmd.Flags().String(GitCommitEmail, "", "E-Mail address to use for Git commits")
140+
runCmd.Flags().String(GitPassword, "", "Password for github user")
141+
runCmd.Flags().String(GitBranch, "develop", "branch")
142+
runCmd.Flags().String(GitRepoUrl, "", "git repo url")
143+
runCmd.Flags().String(GitFile, "", "file eg. values.yaml")
144+
runCmd.Flags().String(GitDir, "", "file eg. /production/charts/")
145+
runCmd.Flags().String(AppName, "", "app name")
146+
runCmd.Flags().String(SshPrivateKey, "", "ssh private key (only using ")
147+
runCmd.Flags().Bool(DryRun, false, "run in dry-run mode. If set to true, do not perform any changes")
148+
runCmd.Flags().String(LogLevel, "info", "set the loglevel to one of trace|debug|info|warn|error")
149+
runCmd.Flags().StringToString(HelmKeyValues, nil, "helm key-values sets")
150+
151+
_ = runCmd.MarkFlagRequired(GitCommitUser)
152+
_ = runCmd.MarkFlagRequired(GitCommitEmail)
153+
_ = runCmd.MarkFlagRequired(GitRepoUrl)
154+
_ = runCmd.MarkFlagRequired(GitFile)
155+
_ = runCmd.MarkFlagRequired(GitDir)
156+
_ = runCmd.MarkFlagRequired(HelmKeyValues)
157+
_ = runCmd.MarkFlagRequired(AppName)
144158

145159
}

0 commit comments

Comments
 (0)