-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.go
60 lines (53 loc) · 1.34 KB
/
search.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package cmd
import (
"strings"
"github.com/adamrdrew/mosh/config"
"github.com/adamrdrew/mosh/printer"
"github.com/adamrdrew/mosh/server"
"github.com/spf13/cobra"
)
func init() {
rootCmd.AddCommand(searchCommand)
searchCommand.AddCommand(artistCommand)
searchCommand.AddCommand(albumCommand)
}
var searchCommand = &cobra.Command{
Use: "search",
Aliases: []string{"s", "se"},
Short: "Search the for an album or artist",
Long: `Search the library for albums or artists`,
}
var artistCommand = &cobra.Command{
Use: "artist",
Aliases: []string{"ar"},
Short: "Search for an artist",
Long: `Search for artist by name. Partial names are fine.`,
Run: func(cmd *cobra.Command, args []string) {
if !guardSetupCompleted() {
return
}
server := getServer()
query := strings.Join(args, " ")
artists := server.SearchArtists(query)
printer.Artists(artists)
},
}
var albumCommand = &cobra.Command{
Use: "album",
Aliases: []string{"al"},
Short: "Search the library",
Long: `Search for an album by name`,
Run: func(cmd *cobra.Command, args []string) {
if !guardSetupCompleted() {
return
}
server := getServer()
query := strings.Join(args, " ")
albums := server.SearchAlbums(query)
printer.Albums(albums)
},
}
func getServer() server.Server {
conf := config.GetConfig()
return server.GetServer(&conf)
}