@ -93,18 +93,19 @@ func main() {
inputFile , err := os . Open ( inputFilename )
if err != nil {
fmt . Printf ( "%s: %s: No such file or directory\n" , os . Args [ 0 ] , inputFilename )
os . Exit ( 2 )
}
fileStat , err := inputFile . Stat ( )
if err != nil {
fmt . Printf ( "%v\n" , err )
os . Exit ( 2 )
}
if fileStat . Mode ( ) . IsDir ( ) {
fmt . Printf ( "%s: %s: Is a directory\n" , os . Args [ 0 ] , inputFilename )
os . Exit ( 2 )
} else {
fileStat , err := inputFile . Stat ( )
if err != nil {
fmt . Printf ( "%v\n" , err )
os . Exit ( 2 )
} else {
if fileStat . Mode ( ) . IsDir ( ) {
fmt . Printf ( "%s: %s: Is a directory\n" , os . Args [ 0 ] , inputFilename )
} else {
inputFiles = append ( inputFiles , inputFile )
}
}
}
inputFiles = append ( inputFiles , inputFile )
}
}
@ -217,7 +218,7 @@ func main() {
if ! ( * invertFlag ) && len ( matchIndices ) == 0 || * invertFlag && len ( matchIndices ) > 0 {
continue
} else {
if len ( inputFiles ) > 1 { // Don't need to print file name if there's only one file
if * recursiveFlag || len ( flag . Args ( ) ) > 2 { // If we have 2 args, then we're only searching 1 file. We should only print the filename if there's more than 1 file.
color . New ( color . FgMagenta ) . Fprintf ( out , "%s:" , inputFile . Name ( ) ) // Print filename
}
if * lineNumFlag {