Skip to content

Commit

Permalink
Merge pull request #47 from zostay/fix-random-exclude
Browse files Browse the repository at this point in the history
fix: missing implementation of --exclude
  • Loading branch information
zostay authored Oct 8, 2024
2 parents c6b5b74 + 10202e0 commit 38a5349
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
12 changes: 11 additions & 1 deletion cmd/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion pkg/ref/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 38a5349

Please sign in to comment.