From 05e534fde51a6ad47dc9799fa81fa5d7daddafe7 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 2 Feb 2022 15:47:16 -0500 Subject: [PATCH] Add flag to ignore file suffixes --- main.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 851681e..fc93e46 100644 --- a/main.go +++ b/main.go @@ -22,6 +22,7 @@ type config struct { AtLeast uint MaxWidth uint MaxHeight uint + IgnoreSuffix bool } @@ -40,6 +41,7 @@ func main() { flag.UintVar(&c.Quality, "quality", 85, "JPG compression quality level.") flag.BoolVar(&c.Quiet, "quiet", false, "Less output - don't print per-file detail") flag.UintVar(&c.AtLeast, "atleast", 0, "Ignore images that aren't at least this many kilobytes") + flag.BoolVar(&c.IgnoreSuffix, "ignoresuffix", false, "Ignore suffix on filenames and attempt to treat everything as a JPG") flag.UintVar(&c.MaxWidth, "maxwidth", 0, "Maximum width, scale images bigger to fit within this width. 0 ignores. Won't replace unless it meets the diff threashold.") flag.UintVar(&c.MaxHeight, "maxheight", 0, "Maximum height, scale images bigger to fit within this height. 0 ignores. Won't replace until it meets the diff threashold.") flag.StringVar(&c.StartingPath, "startingpath", ".", "Start from this path instead of current working dir") @@ -74,8 +76,8 @@ func main() { } for _, f := range d { if !f.IsDir() { - suf := strings.ToLower(filepath.Ext(f.Name())) - if suf == ".jpg" || suf == ".jpeg" { + ext := strings.ToLower(filepath.Ext(f.Name())) + if c.IgnoreSuffix || ext == ".jpg" || ext == ".jpeg" { filelist = append(filelist, f.Name()) } @@ -84,7 +86,7 @@ func main() { } else { filepath.WalkDir(c.StartingPath, func(path string, d fs.DirEntry, err error) error { ext := strings.ToLower(filepath.Ext(path)) - if ext == ".jpg" || ext == ".jpeg" { + if c.IgnoreSuffix || ext == ".jpg" || ext == ".jpeg" { filelist = append(filelist, path) } return nil