func (r *runner) formatFile(overwrite bool, diffMode bool, lintMode bool, fix int, fileHeader string, javaPackagePrefix string, meta *meta, protoFile *file.ProtoFile) (bool, error) {
	absSingleFilename, err := file.AbsClean(meta.SingleFilename)
	if err != nil {
		return false, err
	}
	// we are not concerned with the current file
	if meta.SingleFilename != "" && protoFile.Path != absSingleFilename {
		return true, nil
	}
	input, err := ioutil.ReadFile(protoFile.Path)
	if err != nil {
		return false, err
	}
	data, failures, err := r.newTransformer(fix, fileHeader, javaPackagePrefix).Transform(protoFile.Path, input)
	if err != nil {
		return false, err
	}
	if len(failures) > 0 {
		return false, r.printFailures(protoFile.DisplayPath, meta, failures...)
	}
	if !bytes.Equal(input, data) {
		if overwrite {
			// 0 exit code in overwrite case
			return true, ioutil.WriteFile(protoFile.Path, data, os.ModePerm)
		}
		if lintMode {
			return false, r.printFailures("", meta, text.NewFailuref(scanner.Position{
				Filename: protoFile.DisplayPath,
			}, "FORMAT_DIFF", "Format returned a diff."))
		}
		if diffMode {
			d, err := diff.Do(input, data, protoFile.DisplayPath)
			if err != nil {
				return false, err
			}
			if _, err := io.Copy(r.output, bytes.NewReader(d)); err != nil {
				return false, err
			}
			return false, nil
		}
		//below is !overwrite && !lintMode && !diffMode
		if _, err := io.Copy(r.output, bytes.NewReader(data)); err != nil {
			return false, err
		}
		// there was a diff, return non-zero exit code
		return false, nil
	}
	// we still print the formatted file to stdout
	if !overwrite && !lintMode && !diffMode {
		if _, err := io.Copy(r.output, bytes.NewReader(data)); err != nil {
			return false, err
		}
	}
	return true, nil
}
// return true if there was no unexpected diff and we should exit with 0
// return false if we should exit with non-zero
// if false and nil error, we will return an ExitError outside of this function
return true if there was no unexpected diff and we should exit with 0
return false if we should exit with non-zero
if false and nil error, we will return an ExitError outside of this function
// return true if there was no unexpected diff and we should exit with 0 // return false if we should exit with non - zero // if false and nil error we will return an ExitError outside of this function
func (r *runner) formatFile(overwrite bool, diffMode bool, lintMode bool, fix int, fileHeader string, javaPackagePrefix string, meta *meta, protoFile *file.ProtoFile) (bool, error) {
	absSingleFilename, err := file.AbsClean(meta.SingleFilename)
	if err != nil {
		return false, err
	}
	if meta.SingleFilename != "" && protoFile.Path != absSingleFilename {
		return true, nil
	}
	input, err := ioutil.ReadFile(protoFile.Path)
	if err != nil {
		return false, err
	}
	data, failures, err := r.newTransformer(fix, fileHeader, javaPackagePrefix).Transform(protoFile.Path, input)
	if err != nil {
		return false, err
	}
	if len(failures) > 0 {
		return false, r.printFailures(protoFile.DisplayPath, meta, failures...)
	}
	if !bytes.Equal(input, data) {
		if overwrite {
			return true, ioutil.WriteFile(protoFile.Path, data, os.ModePerm)
		}
		if lintMode {
			return false, r.printFailures("", meta, text.NewFailuref(scanner.Position{
				Filename: protoFile.DisplayPath,
			}, "FORMAT_DIFF", "Format returned a diff."))
		}
		if diffMode {
			d, err := diff.Do(input, data, protoFile.DisplayPath)
			if err != nil {
				return false, err
			}
			if _, err := io.Copy(r.output, bytes.NewReader(d)); err != nil {
				return false, err
			}
			return false, nil
		}
		if _, err := io.Copy(r.output, bytes.NewReader(data)); err != nil {
			return false, err
		}
		return false, nil
	}
	if !overwrite && !lintMode && !diffMode {
		if _, err := io.Copy(r.output, bytes.NewReader(data)); err != nil {
			return false, err
		}
	}
	return true, nil
}
func ( r * runner ) formatFile ( overwrite bool , diffMode bool , lintMode bool , fix int , fileHeader string , javaPackagePrefix string , meta * meta , protoFile * file . ProtoFile ) ( bool , error ) { absSingleFilename , err := file . AbsClean ( meta . SingleFilename ) if err != nil { return false , err } if meta . SingleFilename != " " && protoFile . Path != absSingleFilename { return true , nil } input , err := ioutil . ReadFile ( protoFile . Path ) if err != nil { return false , err } data , failures , err := r . newTransformer ( fix , fileHeader , javaPackagePrefix ) . Transform ( protoFile . Path , input ) if err != nil { return false , err } if len ( failures ) > 0 { return false , r . printFailures ( protoFile . DisplayPath , meta , failures ... ) } if ! bytes . Equal ( input , data ) { if overwrite { return true , ioutil . WriteFile ( protoFile . Path , data , os . ModePerm ) } if lintMode { return false , r . printFailures ( " " , meta , text . NewFailuref ( scanner . Position { Filename : protoFile . DisplayPath , } , " " , " " ) ) } if diffMode { d , err := diff . Do ( input , data , protoFile . DisplayPath ) if err != nil { return false , err } if _ , err := io . Copy ( r . output , bytes . NewReader ( d ) ) ; err != nil { return false , err } return false , nil } if _ , err := io . Copy ( r . output , bytes . NewReader ( data ) ) ; err != nil { return false , err } return false , nil } if ! overwrite && ! lintMode && ! diffMode { if _ , err := io . Copy ( r . output , bytes . NewReader ( data ) ) ; err != nil { return false , err } } return true , nil }
return true if there was no unexpected diff and we should exit with 0
return false if we should exit with non-zero
if false and nil error, we will return an ExitError outside of this function
return true if there was no unexpected diff and we should exit with 0 return false if we should exit with non - zero if false and nil error we will return an ExitError outside of this function
// we are not concerned with the current file // 0 exit code in overwrite case //below is !overwrite && !lintMode && !diffMode // there was a diff, return non-zero exit code // we still print the formatted file to stdout