Skip to content

Commit 6d1dfbd

Browse files
committed
fix: search results outputs
Signed-off-by: ygelfand <yuri@shlitz.com>
1 parent 7268e82 commit 6d1dfbd

File tree

3 files changed

+36
-25
lines changed

3 files changed

+36
-25
lines changed

cmd/search.go

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,26 @@ var searchStatusCmd = &cobra.Command{
2323
Short: "Show search index status and library statistics",
2424
RunE: func(cmd *cobra.Command, args []string) error {
2525
idx := search.GetIndex()
26-
theme := ui.CurrentTheme()
27-
28-
titleStyle := ui.TitleStyle(theme)
29-
labelStyle := ui.LabelStyle(theme)
30-
valueStyle := ui.ValueStyle(theme)
3126

32-
fmt.Println(titleStyle.Render("SEARCH INDEX STATUS"))
3327
lastIndexed := "Never"
3428
if !idx.LastIndexed.IsZero() {
3529
lastIndexed = idx.LastIndexed.Format("2006-01-02 15:04:05")
3630
}
37-
fmt.Printf("%s %s\n", labelStyle.Render("Last Indexed:"), valueStyle.Render(lastIndexed))
38-
fmt.Printf("%s %s\n", labelStyle.Render("Total Entries:"), valueStyle.Render(fmt.Sprintf("%d", len(idx.Entries))))
3931

40-
return nil
32+
data := map[string]interface{}{
33+
"last_indexed": lastIndexed,
34+
"total_entries": len(idx.Entries),
35+
}
36+
37+
return ui.OutputData{
38+
Title: "SEARCH INDEX STATUS",
39+
Headers: []string{"PROPERTY", "VALUE"},
40+
Rows: [][]string{
41+
{"Last Indexed", lastIndexed},
42+
{"Total Entries", fmt.Sprintf("%d", len(idx.Entries))},
43+
},
44+
Raw: data,
45+
}.Print()
4146
},
4247
}
4348

@@ -78,7 +83,6 @@ var searchFindCmd = &cobra.Command{
7883
RunE: func(cmd *cobra.Command, args []string) error {
7984
query := strings.Join(args, " ")
8085
idx := search.GetIndex()
81-
theme := ui.CurrentTheme()
8286

8387
if len(idx.Entries) == 0 {
8488
return fmt.Errorf("index is empty. Please run 'plexctl search reindex' first")
@@ -91,31 +95,30 @@ var searchFindCmd = &cobra.Command{
9195
return nil
9296
}
9397

94-
fmt.Println(ui.TitleStyle(theme).Render(fmt.Sprintf("Results for: %s", query)))
95-
96-
headers := []string{"TITLE", "TYPE", "LIBRARY", "KEY"}
98+
headers := []string{"ID", "TITLE", "TYPE", "LIBRARY"}
9799
var rows [][]string
100+
var rawResults []search.IndexEntry
98101

99102
for i, match := range matches {
100103
if i >= 20 {
101104
break
102105
}
103106
e := idx.Entries[match.Index]
104107
rows = append(rows, []string{
108+
e.RatingKey,
105109
e.Title,
106110
strings.ToUpper(e.Type),
107111
e.Library,
108-
e.RatingKey,
109112
})
113+
rawResults = append(rawResults, e)
110114
}
111115

112-
ui.OutputData{
116+
return ui.OutputData{
117+
Title: fmt.Sprintf("Results for: %s", query),
113118
Headers: headers,
114119
Rows: rows,
115-
Raw: rows, // Use rows as raw for now
120+
Raw: rawResults,
116121
}.Print()
117-
118-
return nil
119122
},
120123
}
121124

docs/content/index.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ plexctl search find "Matrix"
6969

7070
# Check index status
7171
plexctl search status
72+
73+
# Play media via CLI
74+
plexctl play 12345
75+
76+
# Play in terminal video mode
77+
plexctl play 12345 --tct
7278
```
7379

7480
---

internal/commands/wrapper.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,17 @@ func Print(p presenters.Presenter, opts *PlexCtlOptions) error {
152152
p.SortBy(sortCol)
153153
}
154154

155-
data := ui.OutputData{
156-
157-
Title: p.Title(),
155+
title := p.Title()
156+
// Suppress title for machine-readable formats
157+
if opts.OutputFormat != "table" && opts.OutputFormat != "text" && opts.OutputFormat != "txt" && opts.OutputFormat != "" {
158+
title = ""
159+
}
158160

161+
data := ui.OutputData{
162+
Title: title,
159163
Headers: p.Headers(),
160-
161-
Rows: p.Rows(),
162-
163-
Raw: p.Raw(),
164+
Rows: p.Rows(),
165+
Raw: p.Raw(),
164166
}
165167

166168
return data.Print()

0 commit comments

Comments
 (0)