✨ Support more flags when list activity
This commit is contained in:
1 parent
d49de7f301
commit
0c8b7def57
3 files changed
+94
-7
No files matched your search
@@ -6,9 +6,15 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
channelId string
|
||||
parts []string
|
||||
output string
|
||||
channelId string
|
||||
home string
|
||||
maxResults int64
|
||||
mine string
|
||||
publishedAfter string
|
||||
publishedBefore string
|
||||
regionCode string
|
||||
parts []string
|
||||
output string
|
||||
)
|
||||
|
||||
var activityCmd = &cobra.Command{
|
||||
|
||||
+22
-1
@@ -12,6 +12,12 @@ var listCmd = &cobra.Command{
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
a := yutuber.NewActivity(
|
||||
yutuber.WithActivityChannelId(channelId),
|
||||
yutuber.WithActivityHome(home),
|
||||
yutuber.WithActivityMaxResults(maxResults),
|
||||
yutuber.WithActivityMine(mine),
|
||||
yutuber.WithActivityPublishedAfter(publishedAfter),
|
||||
yutuber.WithActivityPublishedBefore(publishedBefore),
|
||||
yutuber.WithActivityRegionCode(regionCode),
|
||||
)
|
||||
a.List(parts, output)
|
||||
},
|
||||
@@ -20,6 +26,21 @@ var listCmd = &cobra.Command{
|
||||
func init() {
|
||||
activityCmd.AddCommand(listCmd)
|
||||
listCmd.Flags().StringVarP(&channelId, "channelId", "c", "", "ID of the channel")
|
||||
listCmd.Flags().StringArrayVarP(&parts, "parts", "p", []string{"id", "snippet", "contentDetails"}, "Comma separated parts")
|
||||
listCmd.Flags().StringVarP(&home, "home", "h", "", "true or false")
|
||||
listCmd.Flags().Int64VarP(
|
||||
&maxResults, "maxResults", "x", 5, "Specifies the maximum number of items that should be returned",
|
||||
)
|
||||
listCmd.Flags().StringVarP(&mine, "mine", "m", "", "true or false")
|
||||
listCmd.Flags().StringVarP(
|
||||
&publishedAfter, "publishedAfter", "a", "", "Filter on activities published after this date",
|
||||
)
|
||||
listCmd.Flags().StringVarP(
|
||||
&publishedBefore, "publishedBefore", "b", "", "Filter on activities published before this date",
|
||||
)
|
||||
listCmd.Flags().StringVarP(®ionCode, "regionCode", "r", "", "")
|
||||
|
||||
listCmd.Flags().StringArrayVarP(
|
||||
&parts, "parts", "p", []string{"id", "snippet", "contentDetails"}, "Comma separated parts",
|
||||
)
|
||||
listCmd.Flags().StringVarP(&output, "output", "o", "", "Output format: json or yaml")
|
||||
}
|
||||
+63
-3
@@ -15,7 +15,13 @@ var (
|
||||
)
|
||||
|
||||
type activity struct {
|
||||
channelId string
|
||||
channelId string
|
||||
home string
|
||||
maxResults int64
|
||||
mine string
|
||||
publishedAfter string
|
||||
publishedBefore string
|
||||
regionCode string
|
||||
}
|
||||
|
||||
type Activity interface {
|
||||
@@ -40,8 +46,26 @@ func (a *activity) get(parts []string) []*youtube.Activity {
|
||||
call := service.Activities.List(parts)
|
||||
if a.channelId != "" {
|
||||
call = call.ChannelId(a.channelId)
|
||||
} else {
|
||||
call = call.Mine(true)
|
||||
}
|
||||
|
||||
if a.home == "true" {
|
||||
call = call.Home(true)
|
||||
} else if a.home == "false" {
|
||||
call = call.Home(false)
|
||||
}
|
||||
|
||||
call.MaxResults(a.maxResults)
|
||||
|
||||
if a.publishedAfter != "" {
|
||||
call.PublishedAfter(a.publishedAfter)
|
||||
}
|
||||
|
||||
if a.publishedBefore != "" {
|
||||
call.PublishedBefore(a.publishedBefore)
|
||||
}
|
||||
|
||||
if a.regionCode != "" {
|
||||
call.RegionCode(a.regionCode)
|
||||
}
|
||||
|
||||
response, err := call.Do()
|
||||
@@ -72,3 +96,39 @@ func WithActivityChannelId(channelId string) ActivityOption {
|
||||
a.channelId = channelId
|
||||
}
|
||||
}
|
||||
|
||||
func WithActivityHome(home string) ActivityOption {
|
||||
return func(a *activity) {
|
||||
a.home = home
|
||||
}
|
||||
}
|
||||
|
||||
func WithActivityMaxResults(maxResults int64) ActivityOption {
|
||||
return func(a *activity) {
|
||||
a.maxResults = maxResults
|
||||
}
|
||||
}
|
||||
|
||||
func WithActivityMine(mine string) ActivityOption {
|
||||
return func(a *activity) {
|
||||
a.mine = mine
|
||||
}
|
||||
}
|
||||
|
||||
func WithActivityPublishedAfter(publishedAfter string) ActivityOption {
|
||||
return func(a *activity) {
|
||||
a.publishedAfter = publishedAfter
|
||||
}
|
||||
}
|
||||
|
||||
func WithActivityPublishedBefore(publishedBefore string) ActivityOption {
|
||||
return func(a *activity) {
|
||||
a.publishedBefore = publishedBefore
|
||||
}
|
||||
}
|
||||
|
||||
func WithActivityRegionCode(regionCode string) ActivityOption {
|
||||
return func(a *activity) {
|
||||
a.regionCode = regionCode
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user