Skip to content

Commit

Permalink
✨ Support more flags when update channel
Browse files Browse the repository at this point in the history
  • Loading branch information
OpenWaygate committed May 7, 2024
1 parent 4681695 commit d7c22d7
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 18 deletions.
11 changes: 7 additions & 4 deletions cmd/channel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ var (
mySubscribers string
onBehalfOfContentOwner string

title string
desc string
output string
parts []string
country string
customUrl string
defaultLanguage string
description string
title string
output string
parts []string
)

var channelCmd = &cobra.Command{
Expand Down
6 changes: 3 additions & 3 deletions cmd/channel/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ func init() {
)
listCmd.Flags().StringVarP(&id, "id", "i", "", "Return the channels with the specified IDs")
listCmd.Flags().StringVarP(
&managedByMe, "managedByMe", "m", "", "Specify the maximum number of items that should be returned",
&managedByMe, "managedByMe", "M", "", "Specify the maximum number of items that should be returned",
)
listCmd.Flags().Int64VarP(&maxResults, "maxResults", "N", 5, "The maximum number of items that should be returned")
listCmd.Flags().StringVarP(&mine, "mine", "n", "", "Return the ids of channels owned by the authenticated user")
listCmd.Flags().Int64VarP(&maxResults, "maxResults", "n", 5, "The maximum number of items that should be returned")
listCmd.Flags().StringVarP(&mine, "mine", "m", "", "Return the ids of channels owned by the authenticated user")
listCmd.Flags().StringVarP(
&mySubscribers, "mySubscribers", "s", "", "Return the channels subscribed to the authenticated user",
)
Expand Down
12 changes: 10 additions & 2 deletions cmd/channel/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ var updateCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
c := yutuber.NewChannel(
yutuber.WithChannelId(id),
yutuber.WithChannelCountry(country),
yutuber.WithChannelCustomUrl(customUrl),
yutuber.WithChannelDefaultLanguage(defaultLanguage),
yutuber.WithChannelDescription(description),
yutuber.WithChannelTitle(title),
yutuber.WithChannelDesc(desc),
)
c.Update()
},
Expand All @@ -23,8 +26,13 @@ func init() {
channelCmd.AddCommand(updateCmd)

updateCmd.Flags().StringVarP(&id, "id", "i", "", "ID of the channel")
updateCmd.Flags().StringVarP(&country, "country", "c", "", "Country of the channel")
updateCmd.Flags().StringVarP(&customUrl, "customUrl", "u", "", "Custom URL of the channel")
updateCmd.Flags().StringVarP(
&defaultLanguage, "defaultLanguage", "l", "", "The language of the channel's default title and description",
)
updateCmd.Flags().StringVarP(&description, "description", "d", "", "Description of the channel")
updateCmd.Flags().StringVarP(&title, "title", "t", "", "Title of the channel")
updateCmd.Flags().StringVarP(&desc, "desc", "d", "", "Description of the channel")

updateCmd.MarkFlagRequired("id")
}
38 changes: 29 additions & 9 deletions pkg/yutuber/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ type channel struct {
mySubscribers string
onBehalfOfContentOwner string

title string
desc string
country string
customUrl string
defaultLanguage string
description string
title string
}

type Channel interface {
Expand Down Expand Up @@ -124,12 +127,11 @@ func (c *channel) List(parts []string, output string) {
func (c *channel) Update() {
parts := []string{"snippet"}
channel := c.get(parts)[0]
// TODO: is there a better way to check and update?
if c.title != "" {
channel.Snippet.Title = c.title
}
if c.desc != "" {
channel.Snippet.Description = c.desc
if c.description != "" {
channel.Snippet.Description = c.description
}

call := service.Channels.Update(parts, channel)
Expand Down Expand Up @@ -201,14 +203,32 @@ func WithChannelOnBehalfOfContentOwner(contentOwner string) ChannelOption {
}
}

func WithChannelTitle(title string) ChannelOption {
func WithChannelCountry(country string) ChannelOption {
return func(c *channel) {
c.title = title
c.country = country
}
}

func WithChannelCustomUrl(url string) ChannelOption {
return func(c *channel) {
c.customUrl = url
}
}

func WithChannelDefaultLanguage(language string) ChannelOption {
return func(c *channel) {
c.defaultLanguage = language
}
}

func WithChannelDescription(desc string) ChannelOption {
return func(c *channel) {
c.description = desc
}
}

func WithChannelDesc(desc string) ChannelOption {
func WithChannelTitle(title string) ChannelOption {
return func(c *channel) {
c.desc = desc
c.title = title
}
}

0 comments on commit d7c22d7

Please # to comment.