Skip to content

Commit fe3e2fd

Browse files
authored
converter: Quiet mode (#140)
1 parent 9ff8754 commit fe3e2fd

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

converter/main.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ var (
3939
height = flag.Int("height", 0, "")
4040
percent = flag.Float64("percent", 0, "")
4141
worker = flag.Int("worker", 5, "")
42+
quiet = flag.Bool("q", false, "")
4243
debug = flag.Bool("debug", false, "")
4344

4445
format imgconv.Format
@@ -213,7 +214,9 @@ func main() {
213214
total := len(images)
214215
log.Println("Total images:", total)
215216
pb := progressbar.New(total)
216-
pb.Start()
217+
if !*quiet {
218+
pb.Start()
219+
}
217220
workers.Workers(*worker).Run(context.Background(), workers.SliceJob(images, func(_ int, image string) {
218221
defer pb.Add(1)
219222
rel, err := filepath.Rel(*src, image)
@@ -223,14 +226,16 @@ func main() {
223226
}
224227
output := task.ConvertExt(filepath.Join(*dst, rel))
225228
if err := convert(task, image, output, *force); err != nil {
226-
if err == errSkip {
229+
if err == errSkip && !*quiet {
227230
log.Println("Skip", output)
228231
}
229232
return
230233
}
231234
log.Debug("Converted " + image)
232235
}))
233-
pb.Done()
236+
if !*quiet {
237+
pb.Done()
238+
}
234239
case srcInfo.Mode().IsRegular():
235240
output := *dst
236241
if dstInfo.Mode().IsDir() {

converter/misc.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ func loadImages(root string, pdf bool) (imgs []string) {
4848
return
4949
case <-ticker.C:
5050
m := message
51-
fmt.Fprintf(os.Stdout, "\r%s\r%s", strings.Repeat(" ", width), m)
51+
if !*quiet {
52+
fmt.Fprintf(os.Stdout, "\r%s\r%s", strings.Repeat(" ", width), m)
53+
}
5254
width = len(m)
5355
}
5456
}
@@ -65,7 +67,9 @@ func loadImages(root string, pdf bool) (imgs []string) {
6567
return nil
6668
})
6769
close(done)
68-
fmt.Fprintf(os.Stdout, "\r%s\r", strings.Repeat(" ", width))
70+
if !*quiet {
71+
fmt.Fprintf(os.Stdout, "\r%s\r", strings.Repeat(" ", width))
72+
}
6973
return
7074
}
7175

0 commit comments

Comments
 (0)