✨ Add jsonpath flag

This commit is contained in:
OpenWaygate committed 2025-07-01 23:39:34 +08:00
1 parent dacc3219f4
commit f859570b04
85 files changed
+319 -217

No files matched your search

+10 -8
View File
@@ -32,8 +32,8 @@ type commentThread struct {
type CommentThread interface {
Get([]string) ([]*youtube.CommentThread, error)
List([]string, string, io.Writer) error
Insert(output string, writer io.Writer) error
List([]string, string, string, io.Writer) error
Insert(output string, s string, writer io.Writer) error
}
type Option func(*commentThread)
@@ -97,7 +97,7 @@ func (c *commentThread) Get(parts []string) ([]*youtube.CommentThread, error) {
}
func (c *commentThread) List(
parts []string, output string, writer io.Writer,
parts []string, output string, jpath string, writer io.Writer,
) error {
commentThreads, err := c.Get(parts)
if err != nil {
@@ -106,9 +106,9 @@ func (c *commentThread) List(
switch output {
case "json":
utils.PrintJSON(commentThreads, writer)
utils.PrintJSON(commentThreads, jpath, writer)
case "yaml":
utils.PrintYAML(commentThreads, writer)
utils.PrintYAML(commentThreads, jpath, writer)
case "table":
tb := table.NewWriter()
defer tb.Render()
@@ -129,7 +129,9 @@ func (c *commentThread) List(
return nil
}
func (c *commentThread) Insert(output string, writer io.Writer) error {
func (c *commentThread) Insert(
output string, jpath string, writer io.Writer,
) error {
ct := &youtube.CommentThread{
Snippet: &youtube.CommentThreadSnippet{
ChannelId: c.ChannelId,
@@ -153,9 +155,9 @@ func (c *commentThread) Insert(output string, writer io.Writer) error {
switch output {
case "json":
utils.PrintJSON(res, writer)
utils.PrintJSON(res, jpath, writer)
case "yaml":
utils.PrintYAML(res, writer)
utils.PrintYAML(res, jpath, writer)
case "silent":
default:
_, _ = fmt.Fprintf(writer, "CommentThread inserted: %s\n", res.Id)