feat: ability to exit zero with no releases match selector (#618)

- Change exit code from 2 to 3 when helmfiles have no releases that match a selector
- Introduces new flag `--allow-no-matching-release` to exit 0 when no releases match a selector.

Resolves: #597
This commit is contained in:
Raj Perera
2019-05-27 09:53:24 +09:00
committed by KUOKA Yusuke
parent f6264bfa9d
commit 4a5996d083
2 changed files with 12 additions and 4 deletions
+8 -4
View File
@@ -27,7 +27,7 @@ func VisitAllDesiredStates(c *cli.Context, converge func(*state.HelmState, helme
err = a.VisitDesiredStates(fileOrDir, a.Selectors, convergeWithHelmBinary)
return toCliError(err)
return toCliError(c, err)
}
func InitAppEntry(c *cli.Context, reverse bool) (*app.App, string, error) {
@@ -76,14 +76,18 @@ func FindAndIterateOverDesiredStatesUsingFlagsWithReverse(c *cli.Context, revers
err = a.VisitDesiredStatesWithReleasesFiltered(fileOrDir, convergeWithHelmBinary)
return toCliError(err)
return toCliError(c, err)
}
func toCliError(err error) error {
func toCliError(c *cli.Context, err error) error {
if err != nil {
switch e := err.(type) {
case *app.NoMatchingHelmfileError:
return cli.NewExitError(e.Error(), 2)
noMatchingExitCode := 3
if c.GlobalBool("allow-no-matching-release") {
noMatchingExitCode = 0
}
return cli.NewExitError(e.Error(), noMatchingExitCode)
case *app.Error:
return cli.NewExitError(e.Error(), e.Code())
default: