shell setup
This commit is contained in:
47
internal/cli/shell.go
Normal file
47
internal/cli/shell.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"gitea.elara.ws/Hazel/music-kraken/internal/data"
|
||||
"gitea.elara.ws/Hazel/music-kraken/internal/plugin"
|
||||
)
|
||||
|
||||
func printResults(musicObjects []data.MusicObject) {
|
||||
for _, m := range musicObjects {
|
||||
if a, ok := m.(data.Artist); ok {
|
||||
fmt.Println("artist: " + a.Name)
|
||||
} else if a, ok := m.(data.Album); ok {
|
||||
fmt.Println("release: " + a.Name)
|
||||
} else if a, ok := m.(data.Song); ok {
|
||||
fmt.Println("track: " + a.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Shell() {
|
||||
plugin.RegisterPlugin(plugin.Musify{})
|
||||
|
||||
for {
|
||||
fmt.Print("> ")
|
||||
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
line, err := reader.ReadString('\n')
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return
|
||||
}
|
||||
|
||||
searchResults, err := plugin.Search(line, plugin.SearchConfig{IgnoreErrors: false})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
printResults(searchResults)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user