feat: Add global `--debug` flag for passing `--debug` to helm (#1236)
Add a global flag --debug that sets the logging level to debug and passes the global flag --debug to Helm through the implementation of subcommands’ --args. Resolves #1104 Co-authored-by: ayoub mrini <amrini@wiremind.fr>
This commit is contained in:
		
							parent
							
								
									6d5f8c71cb
								
							
						
					
					
						commit
						66f34580c3
					
				
							
								
								
									
										22
									
								
								main.go
								
								
								
								
							
							
						
						
									
										22
									
								
								main.go
								
								
								
								
							| 
						 | 
					@ -13,7 +13,6 @@ import (
 | 
				
			||||||
	"github.com/roboll/helmfile/pkg/state"
 | 
						"github.com/roboll/helmfile/pkg/state"
 | 
				
			||||||
	"github.com/urfave/cli"
 | 
						"github.com/urfave/cli"
 | 
				
			||||||
	"go.uber.org/zap"
 | 
						"go.uber.org/zap"
 | 
				
			||||||
	"go.uber.org/zap/zapcore"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var logger *zap.SugaredLogger
 | 
					var logger *zap.SugaredLogger
 | 
				
			||||||
| 
						 | 
					@ -22,14 +21,11 @@ func configureLogging(c *cli.Context) error {
 | 
				
			||||||
	// Valid levels:
 | 
						// Valid levels:
 | 
				
			||||||
	// https://github.com/uber-go/zap/blob/7e7e266a8dbce911a49554b945538c5b950196b8/zapcore/level.go#L126
 | 
						// https://github.com/uber-go/zap/blob/7e7e266a8dbce911a49554b945538c5b950196b8/zapcore/level.go#L126
 | 
				
			||||||
	logLevel := c.GlobalString("log-level")
 | 
						logLevel := c.GlobalString("log-level")
 | 
				
			||||||
	if c.GlobalBool("quiet") {
 | 
						if c.GlobalBool("debug") {
 | 
				
			||||||
 | 
							logLevel = "debug"
 | 
				
			||||||
 | 
						} else if c.GlobalBool("quiet") {
 | 
				
			||||||
		logLevel = "warn"
 | 
							logLevel = "warn"
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	var level zapcore.Level
 | 
					 | 
				
			||||||
	err := level.Set(logLevel)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	logger = helmexec.NewLogger(os.Stderr, logLevel)
 | 
						logger = helmexec.NewLogger(os.Stderr, logLevel)
 | 
				
			||||||
	if c.App.Metadata == nil {
 | 
						if c.App.Metadata == nil {
 | 
				
			||||||
		// Auto-initialised in 1.19.0
 | 
							// Auto-initialised in 1.19.0
 | 
				
			||||||
| 
						 | 
					@ -76,6 +72,10 @@ func main() {
 | 
				
			||||||
			Name:  "kube-context",
 | 
								Name:  "kube-context",
 | 
				
			||||||
			Usage: "Set kubectl context. Uses current context by default",
 | 
								Usage: "Set kubectl context. Uses current context by default",
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 | 
							cli.BoolFlag{
 | 
				
			||||||
 | 
								Name:  "debug",
 | 
				
			||||||
 | 
								Usage: "Enable verbose output for Helm and set log-level to debug, this disables --quiet/-q effect",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
		cli.BoolFlag{
 | 
							cli.BoolFlag{
 | 
				
			||||||
			Name:  "no-color",
 | 
								Name:  "no-color",
 | 
				
			||||||
			Usage: "Output without color",
 | 
								Usage: "Output without color",
 | 
				
			||||||
| 
						 | 
					@ -539,7 +539,13 @@ func (c configImpl) Values() []string {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (c configImpl) Args() string {
 | 
					func (c configImpl) Args() string {
 | 
				
			||||||
	return c.c.String("args")
 | 
						args := c.c.String("args")
 | 
				
			||||||
 | 
						enableHelmDebug := c.c.GlobalBool("debug")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if enableHelmDebug {
 | 
				
			||||||
 | 
							args = fmt.Sprintf("%s %s", args, "--debug")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return args
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (c configImpl) OutputDir() string {
 | 
					func (c configImpl) OutputDir() string {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue