diff --git a/internal/epub/image_processing.go b/internal/epub/image_processing.go index 0bb718d..1ba839e 100644 --- a/internal/epub/image_processing.go +++ b/internal/epub/image_processing.go @@ -136,7 +136,7 @@ func loadDir(input string) (int, chan *imageTask, error) { return nil }) if err != nil { - fmt.Println(err) + fmt.Fprintln(os.Stderr, err) os.Exit(1) } if len(images) == 0 { @@ -151,7 +151,7 @@ func loadDir(input string) (int, chan *imageTask, error) { for i, img := range images { f, err := os.Open(img) if err != nil { - fmt.Println(err) + fmt.Fprintln(os.Stderr, err) os.Exit(1) } output <- &imageTask{ @@ -194,7 +194,7 @@ func loadCbz(input string) (int, chan *imageTask, error) { for i, img := range images { f, err := img.Open() if err != nil { - fmt.Println(err) + fmt.Fprintln(os.Stderr, err) os.Exit(1) } output <- &imageTask{ diff --git a/main.go b/main.go index 30850e2..b3e1571 100644 --- a/main.go +++ b/main.go @@ -124,10 +124,14 @@ func main() { flag.IntVar(&opt.Quality, "quality", 85, "Quality of the image") flag.BoolVar(&opt.NoCrop, "nocrop", false, "Disable cropping") flag.IntVar(&opt.LimitMb, "limitmb", 0, "Limit size of the ePub: Default nolimit (0), Minimum 20") + flag.Usage = func() { + fmt.Fprintf(os.Stderr, "Usage of %s:\n", filepath.Base(os.Args[0])) + flag.PrintDefaults() + } flag.Parse() if opt.Input == "" { - fmt.Println("Missing input or output!") + fmt.Fprintln(os.Stderr, "Missing input or output!") flag.Usage() os.Exit(1) } @@ -135,7 +139,7 @@ func main() { if opt.Output == "" { fi, err := os.Stat(opt.Input) if err != nil { - fmt.Println(err) + fmt.Fprintln(os.Stderr, err) flag.Usage() os.Exit(1) } @@ -149,14 +153,14 @@ func main() { profileIdx, profileMatch := ProfilesIdx[opt.Profile] if !profileMatch { - fmt.Println("Profile doesn't exists!") + fmt.Fprintln(os.Stderr, "Profile doesn't exists!") flag.Usage() os.Exit(1) } profile := Profiles[profileIdx] if opt.LimitMb > 0 && opt.LimitMb < 20 { - fmt.Println("LimitMb should be 0 or >= 20") + fmt.Fprintln(os.Stderr, "LimitMb should be 0 or >= 20") flag.Usage() os.Exit(1) } @@ -165,7 +169,7 @@ func main() { opt.Title = filepath.Base(opt.Input) } - fmt.Println(opt) + fmt.Fprintln(os.Stderr, opt) if err := epub.NewEpub(&epub.EpubOptions{ Input: opt.Input, @@ -180,7 +184,7 @@ func main() { Crop: !opt.NoCrop, }, }).Write(); err != nil { - fmt.Printf("Error: %v\n", err) + fmt.Fprintf(os.Stderr, "Error: %v\n", err) os.Exit(1) }