This repository was archived by the owner on Feb 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparam.go
More file actions
51 lines (44 loc) · 1.21 KB
/
Copy pathparam.go
File metadata and controls
51 lines (44 loc) · 1.21 KB
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
package main
import ("fmt"
"strings"
flag "github.com/ogier/pflag")
type Parameter struct {
ConfigFile *string
RuleFile *string
Verbose *bool
}
func Init() (Parameter) {
params := createParams()
setUsage()
flag.Parse()
printConfig(params)
return params
}
func createParams() (Parameter) {
var configFile = flag.StringP("config", "c", "docker-compose.yml", "docker-compose file to validate")
var ruleFile = flag.StringP("rules", "r", "validation.yml", "file describing the validation rules")
var verbose = flag.BoolP("verbose", "v", false, "more output")
params := Parameter{configFile, ruleFile, verbose}
return params
}
func setUsage() {
flag.Usage = func() {
fmt.Println("Usage: compose-validate --config <docker-compose config> --rules <rule file>")
flag.PrintDefaults()
}
}
func printConfig(params Parameter) {
if (*params.Verbose) {
var l int = 9 + max(len(*params.ConfigFile), len(*params.RuleFile))
fmt.Printf("\n%s\n", strings.Repeat("=", l))
fmt.Printf("config : %s\n", *params.ConfigFile)
fmt.Printf(" rules : %s\n", *params.RuleFile)
fmt.Printf("%s\n", strings.Repeat("=", l))
}
}
func max(a, b int) (int) {
if (a > b) {
return a
}
return b
}