mirror of
https://github.com/gojp/goreportcard.git
synced 2026-01-28 22:39:05 +08:00
add back RevertFiles for CLI #397
This commit is contained in:
parent
2b18ddea27
commit
f236fc9a56
@@ -38,7 +38,7 @@ type ChecksResult struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run executes all checks on the given directory
|
// 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)
|
filenames, skipped, err := GoFiles(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ChecksResult{}, fmt.Errorf("could not get filenames: %v", err)
|
return ChecksResult{}, fmt.Errorf("could not get filenames: %v", err)
|
||||||
@@ -52,6 +52,10 @@ func Run(dir string) (ChecksResult, error) {
|
|||||||
log.Println("Could not rename files:", err)
|
log.Println("Could not rename files:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cli {
|
||||||
|
defer RevertFiles(skipped)
|
||||||
|
}
|
||||||
|
|
||||||
checks := []Check{
|
checks := []Check{
|
||||||
GoFmt{Dir: dir, Filenames: filenames},
|
GoFmt{Dir: dir, Filenames: filenames},
|
||||||
GoVet{Dir: dir, Filenames: filenames},
|
GoVet{Dir: dir, Filenames: filenames},
|
||||||
|
|||||||
@@ -82,6 +82,19 @@ func RenameFiles(names []string) (err error) {
|
|||||||
return err
|
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
|
// lineCount returns the number of lines in a given file
|
||||||
func lineCount(filepath string) (int, error) {
|
func lineCount(filepath string) (int, error) {
|
||||||
out, err := exec.Command("wc", "-l", filepath).Output()
|
out, err := exec.Command("wc", "-l", filepath).Output()
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ func dotPrintf(fullLen int, lfStr, rtFmtStr string, args ...interface{}) {
|
|||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
result, err := check.Run(*dir)
|
result, err := check.Run(*dir, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Fatal error checking %s: %s", *dir, err.Error())
|
log.Fatalf("Fatal error checking %s: %s", *dir, err.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
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 {
|
if err != nil {
|
||||||
return checksResp{}, err
|
return checksResp{}, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user