-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathargs.go
58 lines (46 loc) · 1.74 KB
/
args.go
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
package main
import (
"fmt"
"os"
arg "github.com/alexflint/go-arg"
)
type arguments struct {
Inputs []string `arg:"-i,--input,separate" help:"filename of objects to import and process (use '-' for stdin or '?inlinedata' to use inlined data)" placeholder:"FILE"`
Templates []string `arg:"required,positional" help:"filename.tmpl | @filenames.lst | k8s:namespace/configmap" placeholder:"TEMPLATE"`
Output string `arg:"-o,--output" help:"destination filename" placeholder:"FILE"`
Verbose bool `arg:"-v,--verbose" help:"verbose output"`
VeryVerbose bool `arg:"-t,--trace" help:"trace output"`
Raw bool `arg:"-r,--raw" help:"will NOT ensure newline and end of each block"`
Split bool `arg:"-s,--split" help:"split json-array into separate 'documents'"`
NoInput bool `arg:"-z" help:"no input (equals -i '?{}')"`
}
func (arguments) Version() string {
return versionFunc()
}
func (arguments) Description() string {
return `tmpl8 - Generic (and Kubernetes-friendly) Templating Engine using the go text/template and Sprig functions
Supported input formats: JSON and YAML
`
}
var args arguments
func init() {
arg.MustParse(&args)
if len(args.Templates) == 0 {
fmt.Fprintln(os.Stderr, "Usage: tmpl8 <file> [<file>...]")
fmt.Fprintln(os.Stderr, "")
fmt.Fprintln(os.Stderr, " <file> is either a real file,")
fmt.Fprintln(os.Stderr, " or '@filename' where 'filename' contains list or files to process")
fmt.Fprintln(os.Stderr, "")
fmt.Fprintln(os.Stderr, " The input object is read from <stdin>")
os.Exit(1)
}
if args.NoInput {
args.Inputs = append(args.Inputs, "?{}")
}
if args.VeryVerbose {
args.Verbose = true
}
if len(args.Inputs) == 0 {
args.Inputs = append(args.Inputs, "-")
}
}