@@ -19,7 +19,7 @@ import (
19
19
)
20
20
21
21
// searchCmd represents the search command
22
- var searchCmd = & cobra.Command {
22
+ var SearchCmd = & cobra.Command {
23
23
Use : "search" ,
24
24
Short : "A brief description of your command" ,
25
25
Long : `A longer description that spans multiple lines and likely contains examples
@@ -62,7 +62,6 @@ func Search(cmd *cobra.Command, args []string) error {
62
62
var err error
63
63
movieSet , seriesSet , bothSet , err = CheckIfSearchFlagsSet (cmd , args )
64
64
if err != nil {
65
- fmt .Println (err )
66
65
return err
67
66
}
68
67
if bothSet {
@@ -80,36 +79,44 @@ func Search(cmd *cobra.Command, args []string) error {
80
79
81
80
context := scraper .NewQueryContext ("movie" , MovieName , defaultTarget )
82
81
query := core .NewSearchQuery (context )
83
- var results []scraper.Result
84
82
if err != nil {
85
83
return err
86
84
}
87
85
// Adding wait group to wait for search results to come before rendering the list model.
88
86
var wg sync.WaitGroup
89
87
90
88
wg .Add (1 )
91
- errc := make (chan error )
92
- resultsc := make (chan []scraper.Result )
89
+ errc := make (chan error , 1 )
90
+ resultc := make (chan scraper.Result , 1 )
91
+ resultLen := make (chan int , 1 )
93
92
go func () {
94
93
// Decrement the counter when the go routine completes
95
94
defer wg .Done ()
96
- // Call the function check
95
+ var err error
96
+ var results []scraper.Result
97
97
results , err = query .Search ()
98
98
if err != nil {
99
99
errc <- err
100
100
}
101
- resultsc <- results
101
+ resultLen <- len (results )
102
+ for _ , result := range results {
103
+ resultc <- result
104
+ }
105
+ wg .Wait ()
102
106
}()
103
- wg .Wait ()
104
107
//Stream will be called by tui
105
- results , err = <- resultsc , <- errc
106
108
if err != nil {
107
109
return err
108
110
}
111
+ results := make ([]scraper.Result , <- resultLen )
112
+ for i := 0 ; i < len (results ); i ++ {
113
+ results [i ] = <- resultc
114
+ }
109
115
err = tui .RenderListModelView ("" , results )
110
116
if err != nil {
111
117
return err
112
118
}
119
+ tui .StartStream ()
113
120
}
114
121
if seriesSet {
115
122
SeriesName = cmd .Flag ("series" ).Value .String ()
@@ -123,15 +130,15 @@ func Search(cmd *cobra.Command, args []string) error {
123
130
// }
124
131
125
132
func init () {
126
- yastCmd .AddCommand (searchCmd )
133
+ yastCmd .AddCommand (SearchCmd )
127
134
128
135
// Here you will define your flags and configuration settings.
129
136
130
137
// Cobra supports Persistent Flags which will work for this command
131
138
// and all subcommands, e.g.:
132
139
// searchCmd.PersistentFlags().String("foo", "", "A help for foo")
133
- searchCmd .Flags ().StringVarP (& MovieName , "movie" , "m" , "" , "name of the movie to be searched" )
134
- searchCmd .Flags ().StringVar (& SeriesName , "series" , "" , "name of the series to be searched" )
140
+ SearchCmd .Flags ().StringVarP (& MovieName , "movie" , "m" , "" , "name of the movie to be searched" )
141
+ SearchCmd .Flags ().StringVar (& SeriesName , "series" , "" , "name of the series to be searched" )
135
142
// Cobra supports local flags which will only run when this command
136
143
// is called directly, e.g.:
137
144
// searchCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
0 commit comments