Skip to content

Commit

Permalink
fix: Use slice binding for keywords.
Browse files Browse the repository at this point in the history
  • Loading branch information
syhily committed Dec 28, 2023
1 parent 565e308 commit e8e34c1
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 9 deletions.
9 changes: 2 additions & 7 deletions cmd/flags/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var (
UserAgent = client.DefaultUserAgent
Proxy = ""
ConfigRoot = ""
Keywords = ""
Keywords []string
Retry = 3
SkipError = true

Expand Down Expand Up @@ -71,16 +71,11 @@ func NewFetcher(category fetcher.Category, properties map[string]string) (fetche
return nil, err
}

keywords := strings.Split(Keywords, ",")
for i, keyword := range keywords {
keywords[i] = strings.TrimSpace(keyword)
}

return fetcher.New(&fetcher.Config{
Config: cc,
Category: category,
Formats: fs,
Keywords: keywords,
Keywords: Keywords,
Extract: Extract,
DownloadPath: DownloadPath,
InitialBookID: InitialBookID,
Expand Down
5 changes: 3 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ func init() {
persistentFlags.StringVar(&flags.Proxy, "proxy", flags.Proxy, "The request proxy")
persistentFlags.StringVarP(&flags.UserAgent, "user-agent", "a", flags.UserAgent, "The request user-agent")
persistentFlags.IntVarP(&flags.Retry, "retry", "r", flags.Retry, "The retry times for a failed download")
persistentFlags.BoolVarP(&flags.SkipError, "skip-error", "s", flags.SkipError, "Continue to download the next book if the current book download failed")
persistentFlags.StringVarP(&flags.Keywords, "keywords", "k", flags.Keywords, "The keywords for books")
persistentFlags.BoolVarP(&flags.SkipError, "skip-error", "s", flags.SkipError,
"Continue to download the next book if the current book download failed")
persistentFlags.StringSliceVarP(&flags.Keywords, "keyword", "k", flags.Keywords, "The keywords for books")
persistentFlags.BoolVar(&log.EnableDebug, "verbose", false, "Print all the logs for debugging")
}
1 change: 1 addition & 0 deletions cmd/sobooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var sobooksCmd = &cobra.Command{
Row("Initial ID", flags.InitialBookID).
Row("Rename File", flags.Rename).
Row("Thread", flags.Thread).
Row("Keywords", flags.Keywords).
Row("Thread Limit (req/min)", flags.RateLimit).
Print()

Expand Down
1 change: 1 addition & 0 deletions cmd/talebook.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var talebookDownloadCmd = &cobra.Command{
Row("Initial ID", flags.InitialBookID).
Row("Rename File", flags.Rename).
Row("Thread", flags.Thread).
Row("Keywords", flags.Keywords).
Row("Thread Limit (req/min)", flags.RateLimit).
Print()

Expand Down
1 change: 1 addition & 0 deletions cmd/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var telegramCmd = &cobra.Command{
Row("Initial ID", flags.InitialBookID).
Row("Rename File", flags.Rename).
Row("Thread", flags.Thread).
Row("Keywords", flags.Keywords).
Row("Thread Limit (req/min)", flags.RateLimit).
Print()

Expand Down

0 comments on commit e8e34c1

Please sign in to comment.