File: commandlineFlag.ref

package info (click to toggle)
easygen 5.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 848 kB
  • sloc: sh: 14; makefile: 13
file content (137 lines) | stat: -rw-r--r-- 4,221 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// !!! !!!
// WARNING: Code automatically generated. Editing discouraged.
// !!! !!!

package easygenapi

import (
	"flag"
	"fmt"
	"os"
)

////////////////////////////////////////////////////////////////////////////
// Constant and data type/structure definitions

const progname = "easygen" // os.Args[0]

// The Options struct defines the structure to hold the commandline values
type Options struct { 
	HTML		bool	// treat the template file as html instead of text
	TemplateStr		string	// template string (in text)
	TemplateFile		string	// .tmpl (comma-separated) template file `name(s)` (default: same as .yaml file)
	ExtYaml		string	// `extension` of yaml file
	ExtTmpl		string	// `extension` of template file
	StrFrom		string	// replace from, the from string used for the replace function
	StrTo		string	// replace to, the to string used for the replace function
	IntV		int	// int var
	Batch		time.Duration	// batch interval
	Debug		int	// debugging `level`
}

////////////////////////////////////////////////////////////////////////////
// Global variables definitions

// Opts holds the actual values from the command line parameters
var Opts Options

////////////////////////////////////////////////////////////////////////////
// Commandline definitions

func initVars() {

	// set default values for command line parameters
	flag.BoolVar(&Opts.HTML, "html", false,
		"treat the template file as html instead of text")
	flag.StringVar(&Opts.TemplateStr, "ts", "",
		"template string (in text)")
	flag.StringVar(&Opts.TemplateFile, "f", "",
		".tmpl (comma-separated) template file `name(s)` (default: same as .yaml file)")
	flag.StringVar(&Opts.TemplateFile, "tf", "",
		".tmpl (comma-separated) template file `name(s)` (default: same as .yaml file)")
	flag.StringVar(&Opts.ExtYaml, "ey", ".yaml",
		"`extension` of yaml file")
	flag.StringVar(&Opts.ExtTmpl, "et", ".tmpl",
		"`extension` of template file")
	flag.StringVar(&Opts.StrFrom, "rf", "",
		"replace from, the from string used for the replace function")
	flag.StringVar(&Opts.StrTo, "rt", "",
		"replace to, the to string used for the replace function")
	flag.IntVar(&Opts.IntV, "intv", 0,
		"int var")
	flag.DurationVar(&Opts.Batch, "batch", 120*time.Second,
		"batch interval")
	flag.IntVar(&Opts.Debug, "d", 0,
		"debugging `level`")
	flag.IntVar(&Opts.Debug, "debug", 0,
		"debugging `level`")
}

func initVals() {
	exists := false
	// Now override those default values from environment variables
	if _, exists = os.LookupEnv("EASYGEN_HTML"); Opts.HTML|| exists {
		Opts.HTML = true
	}
	if len(Opts.TemplateStr) == 0 &&
		len(os.Getenv("EASYGEN_TS")) != 0 {
		Opts.TemplateStr = os.Getenv("EASYGEN_TS")
	}
	if len(Opts.TemplateFile) == 0 &&
		len(os.Getenv("EASYGEN_F")) != 0 {
		Opts.TemplateFile = os.Getenv("EASYGEN_F")
	}
	if len(Opts.TemplateFile) == 0 &&
		len(os.Getenv("EASYGEN_TF")) != 0 {
		Opts.TemplateFile = os.Getenv("EASYGEN_TF")
	}
	if len(Opts.ExtYaml) == 0 &&
		len(os.Getenv("EASYGEN_EY")) != 0 {
		Opts.ExtYaml = os.Getenv("EASYGEN_EY")
	}
	if len(Opts.ExtTmpl) == 0 &&
		len(os.Getenv("EASYGEN_ET")) != 0 {
		Opts.ExtTmpl = os.Getenv("EASYGEN_ET")
	}
	if len(Opts.StrFrom) == 0 &&
		len(os.Getenv("EASYGEN_RF")) != 0 {
		Opts.StrFrom = os.Getenv("EASYGEN_RF")
	}
	if len(Opts.StrTo) == 0 &&
		len(os.Getenv("EASYGEN_RT")) != 0 {
		Opts.StrTo = os.Getenv("EASYGEN_RT")
	}
	if Opts.IntV == 0 &&
		len(os.Getenv("EASYGEN_INTV")) != 0 {
		if i, err := strconv.Atoi(os.Getenv("EASYGEN_INTV")); err == nil {
			Opts.IntV = i
		}
	}
	if Opts.Debug == 0 &&
		len(os.Getenv("EASYGEN_D")) != 0 {
		if i, err := strconv.Atoi(os.Getenv("EASYGEN_D")); err == nil {
			Opts.Debug = i
		}
	}
	if Opts.Debug == 0 &&
		len(os.Getenv("EASYGEN_DEBUG")) != 0 {
		if i, err := strconv.Atoi(os.Getenv("EASYGEN_DEBUG")); err == nil {
			Opts.Debug = i
		}
	}

}



// Usage function shows help on commandline usage
func Usage() {
	fmt.Fprintf(os.Stderr,
		"\nUsage:\n %s [flags] YamlFileName [YamlFileName...]\n\nFlags:\n\n",
		progname)
	flag.PrintDefaults()
	fmt.Fprintf(os.Stderr,
		"\nYamlFileName(s): The name for the .yaml data and .tmpl template file\n\tOnly the name part, without extension. Can include the path as well.\n")
	os.Exit(0)
}