Skip to content

Commit b0574e4

Browse files
committed
Refactoring: Remove unnecessary constants
1 parent 46c9d87 commit b0574e4

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

cmd/get.go

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func (cmd *getCmd) doGet(reposPathList []pathutil.ReposPath, lockJSON *lockjson.
229229
} else {
230230
added := cmd.updateReposVersion(lockJSON, r.reposPath, r.reposType, r.hash, profile)
231231
if added && strings.Contains(status, "already exists") {
232-
status = fmt.Sprintf(fmtAddedRepos, statusPrefixInstalled, r.reposPath)
232+
status = fmt.Sprintf(fmtAddedRepos, r.reposPath)
233233
}
234234
updatedLockJSON = true
235235
}
@@ -291,21 +291,19 @@ type getParallelResult struct {
291291
}
292292

293293
const (
294-
statusPrefixFailed = "!"
295-
statusPrefixNoChange = "#"
296-
statusPrefixInstalled = "+"
297-
statusPrefixUpgraded = "*"
298-
)
299-
300-
const (
301-
fmtInstallFailed = "%s %s > install failed > %s"
302-
fmtUpgradeFailed = "%s %s > upgrade failed > %s"
303-
fmtNoChange = "%s %s > no change"
304-
fmtAlreadyExists = "%s %s > already exists"
305-
fmtAddedRepos = "%s %s > added repository to current profile"
306-
fmtInstalled = "%s %s > installed"
307-
fmtRevUpdate = "%s %s > updated lock.json revision (%s..%s)"
308-
fmtUpgraded = "%s %s > upgraded (%s..%s)"
294+
statusPrefixFailed = "!"
295+
// Failed
296+
fmtInstallFailed = "! %s > install failed > %s"
297+
fmtUpgradeFailed = "! %s > upgrade failed > %s"
298+
// No change
299+
fmtNoChange = "# %s > no change"
300+
fmtAlreadyExists = "# %s > already exists"
301+
// Installed
302+
fmtAddedRepos = "+ %s > added repository to current profile"
303+
fmtInstalled = "+ %s > installed"
304+
// Upgraded
305+
fmtRevUpdate = "* %s > updated lock.json revision (%s..%s)"
306+
fmtUpgraded = "* %s > upgraded (%s..%s)"
309307
)
310308

311309
// This function is executed in goroutine of each plugin.
@@ -344,7 +342,7 @@ func (cmd *getCmd) installPlugin(reposPath pathutil.ReposPath, repos *lockjson.R
344342
}
345343
done <- getParallelResult{
346344
reposPath: reposPath,
347-
status: fmt.Sprintf(fmtInstallFailed, statusPrefixFailed, reposPath, result.Error()),
345+
status: fmt.Sprintf(fmtInstallFailed, reposPath, result.Error()),
348346
err: result,
349347
}
350348
return
@@ -361,7 +359,7 @@ func (cmd *getCmd) installPlugin(reposPath pathutil.ReposPath, repos *lockjson.R
361359
msg := "-u was specified but repos == nil"
362360
done <- getParallelResult{
363361
reposPath: reposPath,
364-
status: fmt.Sprintf(fmtUpgradeFailed, statusPrefixFailed, reposPath, msg),
362+
status: fmt.Sprintf(fmtUpgradeFailed, reposPath, msg),
365363
err: errors.New("failed to upgrade plugin: " + msg),
366364
}
367365
return
@@ -378,13 +376,13 @@ func (cmd *getCmd) installPlugin(reposPath pathutil.ReposPath, repos *lockjson.R
378376
}
379377
done <- getParallelResult{
380378
reposPath: reposPath,
381-
status: fmt.Sprintf(fmtUpgradeFailed, statusPrefixFailed, reposPath, err.Error()),
379+
status: fmt.Sprintf(fmtUpgradeFailed, reposPath, err.Error()),
382380
err: result,
383381
}
384382
return
385383
}
386384
if err == git.NoErrAlreadyUpToDate {
387-
status = fmt.Sprintf(fmtNoChange, statusPrefixNoChange, reposPath)
385+
status = fmt.Sprintf(fmtNoChange, reposPath)
388386
} else {
389387
upgraded = true
390388
}
@@ -401,14 +399,14 @@ func (cmd *getCmd) installPlugin(reposPath pathutil.ReposPath, repos *lockjson.R
401399
}
402400
done <- getParallelResult{
403401
reposPath: reposPath,
404-
status: fmt.Sprintf(fmtInstallFailed, statusPrefixFailed, reposPath, result.Error()),
402+
status: fmt.Sprintf(fmtInstallFailed, reposPath, result.Error()),
405403
err: result,
406404
}
407405
return
408406
}
409-
status = fmt.Sprintf(fmtInstalled, statusPrefixInstalled, reposPath)
407+
status = fmt.Sprintf(fmtInstalled, reposPath)
410408
} else {
411-
status = fmt.Sprintf(fmtAlreadyExists, statusPrefixNoChange, reposPath)
409+
status = fmt.Sprintf(fmtAlreadyExists, reposPath)
412410
checkRevision = true
413411
}
414412

@@ -426,7 +424,7 @@ func (cmd *getCmd) installPlugin(reposPath pathutil.ReposPath, repos *lockjson.R
426424
}
427425
done <- getParallelResult{
428426
reposPath: reposPath,
429-
status: fmt.Sprintf(fmtInstallFailed, statusPrefixFailed, reposPath, result.Error()),
427+
status: fmt.Sprintf(fmtInstallFailed, reposPath, result.Error()),
430428
err: result,
431429
}
432430
return
@@ -435,11 +433,11 @@ func (cmd *getCmd) installPlugin(reposPath pathutil.ReposPath, repos *lockjson.R
435433

436434
// Show old and new revisions: "upgraded ({from}..{to})".
437435
if upgraded {
438-
status = fmt.Sprintf(fmtUpgraded, statusPrefixUpgraded, reposPath, fromHash, toHash)
436+
status = fmt.Sprintf(fmtUpgraded, reposPath, fromHash, toHash)
439437
}
440438

441439
if checkRevision && repos != nil && repos.Version != toHash {
442-
status = fmt.Sprintf(fmtRevUpdate, statusPrefixUpgraded, reposPath, repos.Version, toHash)
440+
status = fmt.Sprintf(fmtRevUpdate, reposPath, repos.Version, toHash)
443441
}
444442

445443
done <- getParallelResult{
@@ -464,7 +462,7 @@ func (cmd *getCmd) installPlugconf(reposPath pathutil.ReposPath, pluginResult *g
464462
}
465463
done <- getParallelResult{
466464
reposPath: reposPath,
467-
status: fmt.Sprintf(fmtInstallFailed, statusPrefixFailed, reposPath, result.Error()),
465+
status: fmt.Sprintf(fmtInstallFailed, reposPath, result.Error()),
468466
err: result,
469467
}
470468
return

0 commit comments

Comments
 (0)