Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Each input file will be validated and one of 3 results will be printed for it:
The exit code will be:

- 0 if all files are valid (all _PASS_)
- 1 if any files are invalid (any _HARD FAIL_)
- 1 if there are bad CLI args or if any files are invalid (any _HARD FAIL_)
- 2 if there was any _SOFT FAIL_ and no _HARD FAIL_

## Using private GitLab host
Expand Down
24 changes: 15 additions & 9 deletions gitlab-ci-validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,22 @@ func getEnv(key, fallback string) string {
}

func main() {
flag.Usage = func() {
flags := flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
flags.SetOutput(io.Discard)

flags.Usage = func() {
fmt.Printf("Usage: %s [-host=string] [-token=string] [-project-id=string] FILE...\n", os.Args[0])
flag.PrintDefaults()
flags.PrintDefaults()
}

var c config
flag.StringVar(&c.Host, "host", getEnv("GITLAB_HOST", DEFAULT_HOST), "GitLab instance used to validate the config files")
flag.StringVar(&c.Token, "token", getEnv("GITLAB_TOKEN", ""), "GitLab API access token")
flag.StringVar(&c.ProjectId, "project-id", getEnv("GITLAB_PROJECT_ID", ""), "GitLab project ID")
flag.Parse()
flags.StringVar(&c.Host, "host", getEnv("GITLAB_HOST", DEFAULT_HOST), "GitLab instance used to validate the config files")
flags.StringVar(&c.Token, "token", getEnv("GITLAB_TOKEN", ""), "GitLab API access token")
flags.StringVar(&c.ProjectId, "project-id", getEnv("GITLAB_PROJECT_ID", ""), "GitLab project ID")
if err := flags.Parse(os.Args[1:]); err != nil {
fmt.Println(err)
os.Exit(1)
}

targetUrl, err := url.Parse(c.Host)
if err != nil {
Expand Down Expand Up @@ -166,13 +172,13 @@ func main() {
}

l := log.New(os.Stderr, "", 0)
if flag.NArg() < 1 {
flag.Usage()
if flags.NArg() < 1 {
flags.Usage()
os.Exit(1)
}

var result Validation
for _, source := range flag.Args() {
for _, source := range flags.Args() {
validation, errs := ValidateFile(targetUrl, source)
if validation > result {
result = validation
Expand Down