Skip to content

Commit

Permalink
Initial commit to add 'warn' option for issue loeffel-io#63.
Browse files Browse the repository at this point in the history
  • Loading branch information
wburningham committed Dec 17, 2021
1 parent 3f935ff commit 25c0001
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
package main

import (
"flag"
"fmt"
"gopkg.in/yaml.v2"
"io/ioutil"
"log"
"os"
"strings"
"sync"

"gopkg.in/yaml.v2"
)

func getFullPath(path string) string {
return fmt.Sprintf("%s%s%s", root, sep, path)
}

func main() {
flags := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
warn := flags.Bool("warn", false, "treat lint errors as warnings; write output to stdout and return exit code = 0")
if err := flags.Parse(os.Args[1:]); err != nil {
log.Fatal(err)
}
var config = &Config{
RWMutex: new(sync.RWMutex),
}
Expand Down Expand Up @@ -67,6 +74,15 @@ func main() {
os.Exit(0)
}

exitCode := 1
w := os.Stderr
if *warn {
w = os.Stdout
exitCode = 0
}

logger := log.New(w, "", log.LstdFlags)

// with errors
for _, err := range linter.getErrors() {
var ruleMessages []string
Expand All @@ -75,8 +91,8 @@ func main() {
ruleMessages = append(ruleMessages, rule.GetErrorMessage())
}

log.Printf("%s failed for rules: %s", err.getPath(), strings.Join(ruleMessages, fmt.Sprintf(" %s ", or)))
logger.Printf("%s failed for rules: %s", err.getPath(), strings.Join(ruleMessages, fmt.Sprintf(" %s ", or)))
}

os.Exit(1)
os.Exit(exitCode)
}

0 comments on commit 25c0001

Please sign in to comment.