Print error if input file is a directory; print program name before error string
This commit is contained in:
15
cmd/main.go
15
cmd/main.go
@@ -73,11 +73,11 @@ func main() {
|
||||
// 3. Run the string against the NFA
|
||||
|
||||
if len(flag.Args()) < 1 { // flag.Args() also strips out program name
|
||||
fmt.Println("ERROR: Missing cmdline args")
|
||||
fmt.Printf("%s: ERROR: Missing cmdline args\n", os.Args[0])
|
||||
os.Exit(22)
|
||||
}
|
||||
if *recursiveFlag && len(flag.Args()) < 2 { // File/Directory must be provided with '-r'
|
||||
fmt.Println("ERROR: Missing cmdline args")
|
||||
fmt.Printf("%s: ERROR: Missing cmdline args\n", os.Args[0])
|
||||
os.Exit(22)
|
||||
}
|
||||
var re string
|
||||
@@ -92,7 +92,16 @@ func main() {
|
||||
for _, inputFilename := range inputFilenames {
|
||||
inputFile, err := os.Open(inputFilename)
|
||||
if err != nil {
|
||||
fmt.Printf("%s: No such file or directory\n", inputFilename)
|
||||
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)
|
||||
}
|
||||
inputFiles = append(inputFiles, inputFile)
|
||||
|
Reference in New Issue
Block a user