github.com/secure-build/gitlab-runner@v12.5.0+incompatible/helpers/cli/warn_on_bool.go (about)

     1  package cli_helpers
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/sirupsen/logrus"
     7  )
     8  
     9  // WarnOnBool logs warning if args contains true or false
    10  // github.com/urfave/cli breaks badly if boolean are set using --flag true instead of --flag=true or just --flag
    11  // this is a simple check that warn the user about this if detects "true" or "false" alone in the arguments
    12  func WarnOnBool(args []string) {
    13  	// we skip the first element because it contains the program name
    14  	for idx, a := range args[1:] {
    15  		arg := strings.ToLower(a)
    16  		if arg == "true" || arg == "false" {
    17  			supposedFlag := "--key"
    18  			if idx > 0 {
    19  				supposedFlag = args[idx]
    20  			}
    21  
    22  			logrus.Warningf("boolean parameters must be passed in the command line with %s=%s", supposedFlag, arg)
    23  			logrus.Warningln("parameters after this may be ignored")
    24  			break
    25  		}
    26  	}
    27  }