From 9cf733b55361e79d1c7db849557f6e796b66e811 Mon Sep 17 00:00:00 2001 From: celogeek <65178+celogeek@users.noreply.github.com> Date: Sat, 22 Apr 2023 15:42:39 +0200 Subject: [PATCH] add quiet mode --- internal/converter/converter.go | 7 ++++--- .../converter/options/converter_options.go | 21 ++++++++++--------- internal/epub/epub.go | 3 ++- internal/epub/epub_image_processing.go | 2 +- internal/epub/epub_progress.go | 5 ++++- main.go | 5 +++-- 6 files changed, 25 insertions(+), 18 deletions(-) diff --git a/internal/converter/converter.go b/internal/converter/converter.go index 1e758d0..c6262d8 100644 --- a/internal/converter/converter.go +++ b/internal/converter/converter.go @@ -79,9 +79,6 @@ func (c *Converter) InitParse() { c.AddStringParam(&c.Options.Output, "output", "", "Output of the epub (directory or epub): (default [INPUT].epub)") c.AddStringParam(&c.Options.Author, "author", "GO Comic Converter", "Author of the epub") c.AddStringParam(&c.Options.Title, "title", "", "Title of the epub") - c.AddIntParam(&c.Options.Workers, "workers", runtime.NumCPU(), "Number of workers") - c.AddBoolParam(&c.Options.Dry, "dry", false, "Dry run to show all options") - c.AddBoolParam(&c.Options.DryVerbose, "dry-verbose", false, "Display also sorted files after the TOC") c.AddSection("Config") c.AddStringParam(&c.Options.Profile, "profile", c.Options.Profile, fmt.Sprintf("Profile to use: \n%s", c.Options.AvailableProfiles())) @@ -105,6 +102,10 @@ func (c *Converter) InitParse() { c.AddBoolParam(&c.Options.Reset, "reset", false, "Reset your parameters to default") c.AddSection("Other") + c.AddIntParam(&c.Options.Workers, "workers", runtime.NumCPU(), "Number of workers") + c.AddBoolParam(&c.Options.Dry, "dry", false, "Dry run to show all options") + c.AddBoolParam(&c.Options.DryVerbose, "dry-verbose", false, "Display also sorted files after the TOC") + c.AddBoolParam(&c.Options.Quiet, "quiet", false, "Disable progress bar") c.AddBoolParam(&c.Options.Version, "version", false, "Show current and available version") c.AddBoolParam(&c.Options.Help, "help", false, "Show this help message") } diff --git a/internal/converter/options/converter_options.go b/internal/converter/options/converter_options.go index 522eea3..782b6b6 100644 --- a/internal/converter/options/converter_options.go +++ b/internal/converter/options/converter_options.go @@ -12,14 +12,10 @@ import ( type Options struct { // Output - Input string `yaml:"-"` - Output string `yaml:"-"` - Author string `yaml:"-"` - Title string `yaml:"-"` - Auto bool `yaml:"-"` - Workers int `yaml:"-"` - Dry bool `yaml:"-"` - DryVerbose bool `yaml:"-"` + Input string `yaml:"-"` + Output string `yaml:"-"` + Author string `yaml:"-"` + Title string `yaml:"-"` // Config Profile string `yaml:"profile"` @@ -27,6 +23,7 @@ type Options struct { Crop bool `yaml:"crop"` Brightness int `yaml:"brightness"` Contrast int `yaml:"contrast"` + Auto bool `yaml:"-"` AutoRotate bool `yaml:"auto_rotate"` AutoSplitDoublePage bool `yaml:"auto_split_double_page"` NoBlankPage bool `yaml:"no_blank_page"` @@ -42,8 +39,12 @@ type Options struct { Reset bool `yaml:"-"` // Other - Version bool `yaml:"-"` - Help bool `yaml:"-"` + Workers int `yaml:"-"` + Dry bool `yaml:"-"` + DryVerbose bool `yaml:"-"` + Quiet bool `yaml:"-"` + Version bool `yaml:"-"` + Help bool `yaml:"-"` // Internal profiles profiles.Profiles diff --git a/internal/epub/epub.go b/internal/epub/epub.go index 8063577..a1ba9fa 100644 --- a/internal/epub/epub.go +++ b/internal/epub/epub.go @@ -39,6 +39,7 @@ type EpubOptions struct { Dry bool DryVerbose bool SortPathMode int + Quiet bool *ImageOptions } @@ -211,7 +212,7 @@ func (e *ePub) Write() error { totalParts := len(epubParts) - bar := NewBar(totalParts, "Writing Part", 2, 2) + bar := NewBar(e.Quiet, totalParts, "Writing Part", 2, 2) for i, part := range epubParts { ext := filepath.Ext(e.Output) suffix := "" diff --git a/internal/epub/epub_image_processing.go b/internal/epub/epub_image_processing.go index 0dc4360..580d04b 100644 --- a/internal/epub/epub_image_processing.go +++ b/internal/epub/epub_image_processing.go @@ -198,7 +198,7 @@ func (e *ePub) LoadImages() ([]*Image, error) { imageOutput := make(chan *Image) // processing - bar := NewBar(imageCount, "Processing", 1, 2) + bar := NewBar(e.Quiet, imageCount, "Processing", 1, 2) wg := &sync.WaitGroup{} for i := 0; i < e.ImageOptions.Workers; i++ { diff --git a/internal/epub/epub_progress.go b/internal/epub/epub_progress.go index f188d90..d9d1790 100644 --- a/internal/epub/epub_progress.go +++ b/internal/epub/epub_progress.go @@ -7,7 +7,10 @@ import ( "github.com/schollz/progressbar/v3" ) -func NewBar(max int, description string, currentJob, totalJob int) *progressbar.ProgressBar { +func NewBar(quiet bool, max int, description string, currentJob, totalJob int) *progressbar.ProgressBar { + if quiet { + return progressbar.DefaultSilent(int64(max)) + } fmtJob := fmt.Sprintf("%%0%dd", len(fmt.Sprint(totalJob))) fmtDesc := fmt.Sprintf("[%s/%s] %%-15s", fmtJob, fmtJob) return progressbar.NewOptions(max, diff --git a/main.go b/main.go index e2cb6b0..7916dd1 100644 --- a/main.go +++ b/main.go @@ -100,8 +100,6 @@ $ go install github.com/celogeek/go-comic-converter/v%d@%s Title: cmd.Options.Title, Author: cmd.Options.Author, StripFirstDirectoryFromToc: cmd.Options.StripFirstDirectoryFromToc, - Dry: cmd.Options.Dry, - DryVerbose: cmd.Options.DryVerbose, SortPathMode: cmd.Options.SortPathMode, ImageOptions: &epub.ImageOptions{ ViewWidth: perfectWidth, @@ -117,6 +115,9 @@ $ go install github.com/celogeek/go-comic-converter/v%d@%s HasCover: cmd.Options.HasCover, Workers: cmd.Options.Workers, }, + Dry: cmd.Options.Dry, + DryVerbose: cmd.Options.DryVerbose, + Quiet: cmd.Options.Quiet, }).Write(); err != nil { fmt.Fprintf(os.Stderr, "Error: %v\n", err) os.Exit(1)