Skip to content

Commit

Permalink
add back RevertFiles for CLI #397
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnps committed Mar 31, 2024
1 parent 2b18dde commit f236fc9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
6 changes: 5 additions & 1 deletion check/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type ChecksResult struct {
}

// Run executes all checks on the given directory
func Run(dir string) (ChecksResult, error) {
func Run(dir string, cli bool) (ChecksResult, error) {
filenames, skipped, err := GoFiles(dir)
if err != nil {
return ChecksResult{}, fmt.Errorf("could not get filenames: %v", err)
Expand All @@ -52,6 +52,10 @@ func Run(dir string) (ChecksResult, error) {
log.Println("Could not rename files:", err)
}

if cli {
defer RevertFiles(skipped)
}

checks := []Check{
GoFmt{Dir: dir, Filenames: filenames},
GoVet{Dir: dir, Filenames: filenames},
Expand Down
13 changes: 13 additions & 0 deletions check/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ func RenameFiles(names []string) (err error) {
return err
}

// RevertFiles removes the ".grc.bk" extension from files
func RevertFiles(names []string) (err error) {
for i := range names {
tmpErr := os.Rename(names[i]+".grc.bk", names[i])
if tmpErr != nil {
// save this error, but still continue with other files
err = tmpErr
}
}

return err
}

// lineCount returns the number of lines in a given file
func lineCount(filepath string) (int, error) {
out, err := exec.Command("wc", "-l", filepath).Output()
Expand Down
2 changes: 1 addition & 1 deletion cmd/goreportcard-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func dotPrintf(fullLen int, lfStr, rtFmtStr string, args ...interface{}) {
func main() {
flag.Parse()

result, err := check.Run(*dir)
result, err := check.Run(*dir, true)
if err != nil {
log.Fatalf("Fatal error checking %s: %s", *dir, err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion handlers/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func newChecksResp(db *badger.DB, repo string, forceRefresh bool) (checksResp, e
return checksResp{}, fmt.Errorf("could not download repo: %v", err)
}

checkResult, err := check.Run(dirName(repo, ver))
checkResult, err := check.Run(dirName(repo, ver), false)
if err != nil {
return checksResp{}, err
}
Expand Down

0 comments on commit f236fc9

Please sign in to comment.