1package main
2
3import (
4 "fmt"
5 "os"
6 "path/filepath"
7)
8
9const (
10 // File name used for Alpine Linux APKBUILDs.
11 pkgbuildfn = "APKBUILD"
12)
13
14func main() {
15 var fns []string
16 if len(os.Args) <= 1 {
17 if !Exists(pkgbuildfn) {
18 fmt.Fprintf(os.Stderr, "%q doesn't exists in current directory.\n", pkgbuildfn)
19 os.Exit(1)
20 }
21
22 fns = []string{pkgbuildfn}
23 } else {
24 for _, arg := range os.Args[1:] {
25 if IsDir(arg) {
26 arg = filepath.Join(arg, pkgbuildfn)
27 }
28
29 if !Exists(arg) {
30 fmt.Fprintf(os.Stderr, "%q doesn't exist.\n", arg)
31 os.Exit(1)
32 }
33
34 fns = append(fns, arg)
35 }
36 }
37
38 var abuilds []*APKBUILD
39 for _, fn := range fns {
40 file, err := os.Open(fn)
41 if err != nil {
42 panic(err)
43 }
44
45 abuild, err := Parse(file, fn)
46 if err != nil {
47 panic(err)
48 }
49
50 abuilds = append(abuilds, abuild)
51 file.Close()
52 }
53
54 exitStatus := 0
55 for _, abuild := range abuilds {
56 linter := Linter{f: abuild, w: os.Stdout}
57 if linter.Lint() {
58 exitStatus = 1
59 }
60 }
61 os.Exit(exitStatus)
62}