✨ Support hl flag when list i18n staff
This commit is contained in:
1 parent
d92b775940
commit
f2ebd7d68c
8 files changed
+47
-19
No files matched your search
@@ -6,6 +6,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
hl string
|
||||
parts []string
|
||||
output string
|
||||
)
|
||||
|
||||
@@ -10,13 +10,14 @@ var listCmd = &cobra.Command{
|
||||
Short: "list i18nLanguages",
|
||||
Long: "list i18nLanguages' id, hl, and name",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
i := yutuber.NewI18nLanguage()
|
||||
i := yutuber.NewI18nLanguage(yutuber.WithI18nLanguageHl(hl))
|
||||
i.List(parts, output)
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
i18nLanguageCmd.AddCommand(listCmd)
|
||||
listCmd.Flags().StringVarP(&hl, "hl", "l", "", "host language")
|
||||
listCmd.Flags().StringSliceVarP(
|
||||
&parts, "parts", "p", []string{"id", "snippet"}, "Comma separated parts",
|
||||
)
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
hl string
|
||||
parts []string
|
||||
output string
|
||||
)
|
||||
|
||||
@@ -10,13 +10,14 @@ var listCmd = &cobra.Command{
|
||||
Short: "list i18nRegions",
|
||||
Long: "list i18nRegions' id, hl, and name",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
i := yutuber.NewI18nRegion()
|
||||
i := yutuber.NewI18nRegion(yutuber.WithI18nRegionHl(hl))
|
||||
i.List(parts, output)
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
i18nRegionCmd.AddCommand(listCmd)
|
||||
listCmd.Flags().StringVarP(&hl, "hl", "l", "", "host language")
|
||||
listCmd.Flags().StringSliceVarP(
|
||||
&parts, "parts", "p", []string{"id", "snippet"}, "Comma separated parts",
|
||||
)
|
||||
|
||||
+5
-5
@@ -3,11 +3,11 @@ package cmd
|
||||
import "github.com/spf13/cobra"
|
||||
|
||||
var (
|
||||
Version string = ""
|
||||
Commit string = ""
|
||||
CommitDate string = ""
|
||||
Os string = ""
|
||||
Arch string = ""
|
||||
Version = ""
|
||||
Commit = ""
|
||||
CommitDate = ""
|
||||
Os = ""
|
||||
Arch = ""
|
||||
)
|
||||
|
||||
var versionCmd = &cobra.Command{
|
||||
|
||||
+10
-10
@@ -20,16 +20,16 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
credential string = "client_secret.json"
|
||||
cacheFile string = "youtube.token.json"
|
||||
errGetUser error = errors.New("unable to get current user")
|
||||
errCreateSvc error = errors.New("unable to create YouTube service")
|
||||
errReadPrompt error = errors.New("unable to read prompt")
|
||||
errExchange error = errors.New("unable retrieve token from web or prompt")
|
||||
errStartWeb error = errors.New("unable to start web server")
|
||||
errCacheToken error = errors.New("unable to cache token")
|
||||
errReadSecret error = errors.New("unable to read client secret file")
|
||||
errParseSecret error = errors.New("unable to parse client secret to config")
|
||||
credential = "client_secret.json"
|
||||
cacheFile = "youtube.token.json"
|
||||
errGetUser = errors.New("unable to get current user")
|
||||
errCreateSvc = errors.New("unable to create YouTube service")
|
||||
errReadPrompt = errors.New("unable to read prompt")
|
||||
errExchange = errors.New("unable retrieve token from web or prompt")
|
||||
errStartWeb = errors.New("unable to start web server")
|
||||
errCacheToken = errors.New("unable to cache token")
|
||||
errReadSecret = errors.New("unable to read client secret file")
|
||||
errParseSecret = errors.New("unable to parse client secret to config")
|
||||
)
|
||||
|
||||
const missingClientSecretsMessage string = `
|
||||
|
||||
@@ -13,7 +13,9 @@ var (
|
||||
errGetI18nLanguage = errors.New("failed to get i18n language")
|
||||
)
|
||||
|
||||
type i18nLanguage struct{}
|
||||
type i18nLanguage struct {
|
||||
hl string
|
||||
}
|
||||
|
||||
type I18nLanguage interface {
|
||||
get(parts []string) []*youtube.I18nLanguage
|
||||
@@ -35,6 +37,10 @@ func NewI18nLanguage(opts ...I18nLanguageOption) I18nLanguage {
|
||||
|
||||
func (i *i18nLanguage) get(parts []string) []*youtube.I18nLanguage {
|
||||
call := service.I18nLanguages.List(parts)
|
||||
if i.hl != "" {
|
||||
call = call.Hl(i.hl)
|
||||
}
|
||||
|
||||
response, err := call.Do()
|
||||
if err != nil {
|
||||
log.Fatalln(errors.Join(errGetI18nLanguage, err))
|
||||
@@ -60,3 +66,9 @@ func (i *i18nLanguage) List(parts []string, output string) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func WithI18nLanguageHl(hl string) I18nLanguageOption {
|
||||
return func(i *i18nLanguage) {
|
||||
i.hl = hl
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,9 @@ var (
|
||||
errGetI18nRegion = errors.New("failed to get i18n region")
|
||||
)
|
||||
|
||||
type i18nRegion struct{}
|
||||
type i18nRegion struct {
|
||||
hl string
|
||||
}
|
||||
|
||||
type I18nRegion interface {
|
||||
get(parts []string) []*youtube.I18nRegion
|
||||
@@ -35,6 +37,10 @@ func NewI18nRegion(opts ...I18nRegionOption) I18nRegion {
|
||||
|
||||
func (i *i18nRegion) get(parts []string) []*youtube.I18nRegion {
|
||||
call := service.I18nRegions.List(parts)
|
||||
if i.hl != "" {
|
||||
call = call.Hl(i.hl)
|
||||
}
|
||||
|
||||
response, err := call.Do()
|
||||
if err != nil {
|
||||
log.Fatalln(errors.Join(errGetI18nRegion, err))
|
||||
@@ -60,3 +66,9 @@ func (i *i18nRegion) List(parts []string, output string) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func WithI18nRegionHl(hl string) I18nRegionOption {
|
||||
return func(i *i18nRegion) {
|
||||
i.hl = hl
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user