🐛 Fail gracefully when none found
This commit is contained in:
parent
5881f3d538
commit
7a198a0273
7 changed files with 37 additions and 8 deletions
|
|
@ -5,7 +5,7 @@ import (
|
|||
"os"
|
||||
|
||||
"codeberg.org/danjones000/strip-beats/files"
|
||||
"codeberg.org/danjones000/strip-beats/input/boolean"
|
||||
"codeberg.org/danjones000/strip-beats/io/boolean"
|
||||
"codeberg.org/danjones000/strip-beats/media"
|
||||
"codeberg.org/danjones000/strip-beats/utils"
|
||||
"github.com/rkoesters/xdg/trash"
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package app
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"codeberg.org/danjones000/strip-beats/input/list"
|
||||
"codeberg.org/danjones000/strip-beats/io/list"
|
||||
)
|
||||
|
||||
func (st AppStep) Title() string {
|
||||
|
|
|
|||
19
app/print.go
19
app/print.go
|
|
@ -3,8 +3,9 @@ package app
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"codeberg.org/danjones000/strip-beats/input/boolean"
|
||||
"codeberg.org/danjones000/strip-beats/input/list"
|
||||
"codeberg.org/danjones000/strip-beats/io/boolean"
|
||||
"codeberg.org/danjones000/strip-beats/io/list"
|
||||
m "codeberg.org/danjones000/strip-beats/io/message"
|
||||
"codeberg.org/danjones000/strip-beats/media"
|
||||
"codeberg.org/danjones000/strip-beats/media/brainz"
|
||||
"codeberg.org/danjones000/strip-beats/utils"
|
||||
|
|
@ -51,7 +52,11 @@ func print() {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
rec := chooseRec(ids)
|
||||
rec, ok := chooseRec(ids)
|
||||
if !ok {
|
||||
m.Message("Couldn't find a marching recording")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println(rec.Title)
|
||||
|
||||
|
|
@ -99,7 +104,7 @@ func print() {
|
|||
tags.TrackCount = media.TrackCount
|
||||
}
|
||||
|
||||
func chooseRec(ids media.IdResults) brainz.Recording {
|
||||
func chooseRec(ids media.IdResults) (brainz.Recording, bool) {
|
||||
var recs []list.Option
|
||||
var rec brainz.Recording
|
||||
var err error
|
||||
|
|
@ -122,7 +127,11 @@ func chooseRec(ids media.IdResults) brainz.Recording {
|
|||
return opt.Title() != ""
|
||||
})
|
||||
|
||||
return list.List("Which recording is the correct one?", recs, nil).(recOpt).rec
|
||||
if len(recs) < 1 {
|
||||
return rec, false
|
||||
}
|
||||
|
||||
return list.List("Which recording is the correct one?", recs, nil).(recOpt).rec, true
|
||||
}
|
||||
|
||||
func findFirstRelease(rec brainz.Recording) brainz.Release {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
|
||||
"codeberg.org/danjones000/strip-beats/input/boolean"
|
||||
"codeberg.org/danjones000/strip-beats/io/boolean"
|
||||
"codeberg.org/danjones000/strip-beats/media"
|
||||
"codeberg.org/danjones000/strip-beats/media/brainz"
|
||||
)
|
||||
|
|
|
|||
20
io/message/message.go
Normal file
20
io/message/message.go
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
package message
|
||||
|
||||
import "github.com/rivo/tview"
|
||||
|
||||
func Message(text string) {
|
||||
app := tview.NewApplication()
|
||||
modal := tview.NewModal()
|
||||
if text != "" {
|
||||
modal.SetText(text)
|
||||
}
|
||||
|
||||
modal.AddButtons([]string{"Ok"}).
|
||||
SetDoneFunc(func(buttonIndex int, buttonLabel string) {
|
||||
app.Stop()
|
||||
})
|
||||
|
||||
if err := app.SetRoot(modal, false).EnableMouse(true).Run(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue