github.com/matthewdale/lab@v0.14.0/cmd/ci_lint.go (about) 1 package cmd 2 3 import ( 4 "fmt" 5 "io/ioutil" 6 "log" 7 "os" 8 9 "github.com/pkg/errors" 10 "github.com/spf13/cobra" 11 lab "github.com/zaquestion/lab/internal/gitlab" 12 ) 13 14 // ciLintCmd represents the lint command 15 var ciLintCmd = &cobra.Command{ 16 Use: "lint", 17 Short: "Validate .gitlab-ci.yml against GitLab", 18 Long: ``, 19 Run: func(cmd *cobra.Command, args []string) { 20 path := ".gitlab-ci.yml" 21 if len(args) == 1 { 22 path = args[0] 23 } 24 b, err := ioutil.ReadFile(path) 25 if !os.IsNotExist(err) && err != nil { 26 log.Fatal(err) 27 } 28 ok, err := lab.Lint(string(b)) 29 if !ok || err != nil { 30 log.Fatal(errors.Wrap(err, "ci yaml invalid")) 31 } 32 fmt.Println("Valid!") 33 }, 34 } 35 36 func init() { 37 ciCmd.AddCommand(ciLintCmd) 38 }