From 10202e0a1cc6c2adefbbfd4e995a56368b8fae2e Mon Sep 17 00:00:00 2001 From: Sterling Hanenkamp Date: Tue, 8 Oct 2024 00:19:12 -0500 Subject: [PATCH] fix: missing implementation of --exclude --- cmd/random.go | 12 +++++++++++- pkg/ref/random.go | 8 +++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/cmd/random.go b/cmd/random.go index 392d35e..9fbb6e2 100644 --- a/cmd/random.go +++ b/cmd/random.go @@ -75,6 +75,11 @@ func RunTodayRandom(cmd *cobra.Command, args []string) error { opts = append(opts, ref.WithAtMost(maximumVerses)) } + excludeRefs := make([]string, 0, len(exclude)) + if len(exclude) > 0 { + excludeRefs = append(excludeRefs, exclude...) + } + if excludeIndex != "" { idx, err := loadIndex(excludeIndex) if err != nil { @@ -85,7 +90,12 @@ func RunTodayRandom(cmd *cobra.Command, args []string) error { for _, v := range idx.Verses { refs = append(refs, v.Reference) } - opts = append(opts, ref.ExcludeReferences(refs...)) + + excludeRefs = append(excludeRefs, refs...) + } + + if len(excludeRefs) > 0 { + opts = append(opts, ref.ExcludeReferences(excludeRefs...)) } if minimumVerses > maximumVerses { diff --git a/pkg/ref/random.go b/pkg/ref/random.go index 4c0cf9f..3757f39 100644 --- a/pkg/ref/random.go +++ b/pkg/ref/random.go @@ -130,7 +130,13 @@ func Random(opt ...RandomReferenceOption) (*Resolved, error) { vs = RandomPassageFromRef(be.Ref, o.min, o.max) } else { if o.book != "" { - ex, err := Lookup(Canonical, o.book+" 1:1ffb", "") + b, err = o.canon.Book(o.book) + if err != nil { + return nil, fmt.Errorf("error looking up book %q: %w", o.book, err) + } + + firstVerse := b.Verses[0] + ex, err := Lookup(o.canon, o.book+" "+firstVerse.Ref()+"ffb", "") if err != nil { return nil, fmt.Errorf("error looking up book %q: %w", o.book, err) }