File: deprecated.go

package info (click to toggle)
golang-go.uber-mock 0.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,176 kB
  • sloc: sh: 37; makefile: 3
file content (41 lines) | stat: -rw-r--r-- 1,078 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main

import (
	"flag"
	"log"
	"os"
)

const (
	deprecatedFlagProgOnly = "prog_only"
	deprecatedFlagExecOnly = "exec_only"
)

var (
	_ = flag.Bool("prog_only", false, "DEPRECATED (reflect mode) Only generate the reflection program; write it to stdout and exit.")
	_ = flag.String("exec_only", "", "DEPRECATED (reflect mode) If set, execute this reflection program.")
)

// notifyAboutDeprecatedFlags prints a warning message for a deprecated flags if they are set.
func notifyAboutDeprecatedFlags() {
	const resetColorPostfix = "\033[0m"
	logger := initWarningLogger()

	flag.Visit(func(f *flag.Flag) {
		switch f.Name {
		case deprecatedFlagProgOnly:
			logger.Println("The -prog_only flag is deprecated and has no effect.", resetColorPostfix)
		case deprecatedFlagExecOnly:
			logger.Println("The -exec_only flag is deprecated and has no effect.", resetColorPostfix)
		}
	})
}

func initWarningLogger() *log.Logger {
	const (
		yellowColor   = "\033[33m"
		warningPrefix = yellowColor + "WARNING: "
	)

	return log.New(os.Stdout, warningPrefix, log.Ldate|log.Ltime)
}