Compare commits

..

No commits in common. "master" and "v0.0.1" have entirely different histories.

40
main.go
View File

@ -17,43 +17,27 @@ import (
) )
var ( var (
gVersion = "0.2" gVersion = "0.0.1"
Usage = func() {
fmt.Printf("deldify v%s\n", gVersion)
fmt.Printf("Usage: deldify [-h|--help] [filename]\n")
fmt.Printf(" read stdin if filename is empty or '-'\n")
fmt.Printf("Flags:\n")
fmt.Printf(" -h|--help: Display help\n")
os.Exit(1)
}
) )
func main() { func main() {
var input string var input string
flag.Usage = Usage
flag.Parse() flag.Parse()
if len(flag.Args()) < 1 {
if len(flag.Args()) == 0 { fmt.Printf("deldify v%s\n", gVersion)
input = "-" fmt.Printf("Usage: deldify filename\n")
os.Exit(1)
} }
input = flag.Args()[0]
// open file or stdin // open file
var f *os.File f, err := os.Open(input)
if err != nil {
if !strings.EqualFold(input, "-") { fmt.Errorf("%v\n", err)
f, err := os.Open(input)
if err != nil {
fmt.Errorf("%v\n", err)
}
// remember to close the file at the end of the program
defer f.Close()
} else {
f = os.Stdin
} }
// remember to close the file at the end of the program
defer f.Close()
// read the file line by line using scanner // read the file line by line using scanner
scanner := bufio.NewScanner(f) scanner := bufio.NewScanner(f)