File: warn_on_bool.go

package info (click to toggle)
gitlab-ci-multi-runner 14.10.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 31,248 kB
  • sloc: sh: 1,694; makefile: 384; asm: 79; ruby: 68
file content (27 lines) | stat: -rw-r--r-- 815 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package cli_helpers

import (
	"strings"

	"github.com/sirupsen/logrus"
)

// WarnOnBool logs warning if args contains true or false
// github.com/urfave/cli breaks badly if boolean are set using --flag true instead of --flag=true or just --flag
// this is a simple check that warn the user about this if detects "true" or "false" alone in the arguments
func WarnOnBool(args []string) {
	// we skip the first element because it contains the program name
	for idx, a := range args[1:] {
		arg := strings.ToLower(a)
		if arg == "true" || arg == "false" {
			supposedFlag := "--key"
			if idx > 0 {
				supposedFlag = args[idx]
			}

			logrus.Warningf("boolean parameters must be passed in the command line with %s=%s", supposedFlag, arg)
			logrus.Warningln("parameters after this may be ignored")
			break
		}
	}
}