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 (
gVersion = "0.2"
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)
}
gVersion = "0.0.1"
)
func main() {
var input string
flag.Usage = Usage
flag.Parse()
if len(flag.Args()) == 0 {
input = "-"
if len(flag.Args()) < 1 {
fmt.Printf("deldify v%s\n", gVersion)
fmt.Printf("Usage: deldify filename\n")
os.Exit(1)
}
input = flag.Args()[0]
// open file or stdin
var f *os.File
if !strings.EqualFold(input, "-") {
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
// open file
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()
// read the file line by line using scanner
scanner := bufio.NewScanner(f)