From cba908d1fd5b8111295e67264312debba1108d6c Mon Sep 17 00:00:00 2001 From: nate smith Date: Tue, 30 Apr 2024 21:18:52 -0700 Subject: [PATCH] bugfixes --- cmd/root.go | 2 +- cutup/cutup.go | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 378354d..19710e3 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -13,7 +13,7 @@ var rootCmd = &cobra.Command{ func Execute() { if err := rootCmd.Execute(); err != nil { - fmt.Fprintf(os.Stderr, err.Error()) + fmt.Fprintf(os.Stderr, err.Error()+"\n") os.Exit(1) } } diff --git a/cutup/cutup.go b/cutup/cutup.go index c8c8556..24aa8f2 100644 --- a/cutup/cutup.go +++ b/cutup/cutup.go @@ -71,7 +71,7 @@ func Cutup(opts CutupOpts) error { } close(paths) - ixPath := path.Join(opts.CutupDir, "_title_index.csv") + ixPath := path.Join(opts.CutupDir, "_title_index.tsv") ixFile, err := os.Create(ixPath) if err != nil { return fmt.Errorf("could not open '%s': %w", ixPath, err) @@ -110,14 +110,14 @@ func worker(opts CutupOpts, paths <-chan string, sources chan<- string) { for s.Scan() { text = strings.TrimSpace(s.Text()) - if opts.headerEndCheck(text) { + if inHeader && opts.headerEndCheck(text) { + inHeader = false if opts.Flavor == "gutenberg" { title = extractGutenbergTitle(text) continue } else { title = path.Base(p) } - inHeader = false } if inHeader { continue @@ -140,7 +140,9 @@ func worker(opts CutupOpts, paths <-chan string, sources chan<- string) { } for i, r := range text { if v := shouldBreak(phraseBuff, r); v > 0 { - phraseBuff = phraseBuff[0 : len(phraseBuff)-v] + if len(phraseBuff) > 0 { + phraseBuff = phraseBuff[0 : len(phraseBuff)-v] + } if len(phraseBuff) >= 10 { cleaned = clean(phraseBuff) if len(cleaned) > 0 {