forked from LaconicNetwork/kompose
Merge pull request #111 from surajssd/suppress-warnings
Added flag `--suppress-warnings`, `--verbose`, `--error-on-warning` global flags
This commit is contained in:
commit
1e581355c7
@ -45,10 +45,28 @@ const (
|
|||||||
|
|
||||||
var inputFormat = "compose"
|
var inputFormat = "compose"
|
||||||
|
|
||||||
|
// Hook for erroring and exit out on warning
|
||||||
|
type errorOnWarningHook struct{}
|
||||||
|
|
||||||
|
func (errorOnWarningHook) Levels() []logrus.Level {
|
||||||
|
return []logrus.Level{logrus.WarnLevel}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (errorOnWarningHook) Fire(entry *logrus.Entry) error {
|
||||||
|
logrus.Fatalln(entry.Message)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// BeforeApp is an action that is executed before any cli command.
|
// BeforeApp is an action that is executed before any cli command.
|
||||||
func BeforeApp(c *cli.Context) error {
|
func BeforeApp(c *cli.Context) error {
|
||||||
|
|
||||||
if c.GlobalBool("verbose") {
|
if c.GlobalBool("verbose") {
|
||||||
logrus.SetLevel(logrus.DebugLevel)
|
logrus.SetLevel(logrus.DebugLevel)
|
||||||
|
} else if c.GlobalBool("suppress-warnings") {
|
||||||
|
logrus.SetLevel(logrus.ErrorLevel)
|
||||||
|
} else if c.GlobalBool("error-on-warning") {
|
||||||
|
hook := errorOnWarningHook{}
|
||||||
|
logrus.AddHook(hook)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -124,5 +124,20 @@ func CommonFlags() []cli.Flag {
|
|||||||
Value: app.DefaultComposeFile,
|
Value: app.DefaultComposeFile,
|
||||||
EnvVar: "COMPOSE_FILE",
|
EnvVar: "COMPOSE_FILE",
|
||||||
},
|
},
|
||||||
|
// creating a flag to suppress warnings
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "suppress-warnings",
|
||||||
|
Usage: "Suppress all warnings",
|
||||||
|
},
|
||||||
|
// creating a flag to show all kinds of warnings
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "verbose",
|
||||||
|
Usage: "Show all type of logs",
|
||||||
|
},
|
||||||
|
// flag to treat any warning as error
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "error-on-warning",
|
||||||
|
Usage: "Treat any warning as error",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user