Skip to content
This repository was archived by the owner on Jan 29, 2025. It is now read-only.

Commit 7617586

Browse files
committed
feat: add new browse options to commandline client
1 parent 3d9104f commit 7617586

File tree

1 file changed

+50
-7
lines changed

1 file changed

+50
-7
lines changed

cmd/catalog.go

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,35 @@ package cmd
33
import (
44
"fmt"
55
"os"
6+
"strconv"
67

78
"github.com/menzerath/monstercat-api/v2/monstercat"
89
"github.com/olekukonko/tablewriter"
910
"github.com/spf13/cobra"
1011
)
1112

1213
var (
13-
catalogSearch string
14-
catalogType string
15-
catalogLimit int
16-
catalogOffset int
14+
catalogSearch string
15+
catalogBrands []string
16+
catalogGenres []string
17+
catalogTypes []string
18+
catalogTags []string
19+
catalogIncludeGold bool
20+
catalogIncludeUnreleased bool
21+
catalogSort string
22+
catalogLimit int
23+
catalogOffset int
1724
)
1825

1926
func init() {
20-
catalogCmd.Flags().StringVarP(&catalogSearch, "search", "s", "", "search query")
21-
catalogCmd.Flags().StringVarP(&catalogType, "type", "t", "", "type of release")
27+
catalogCmd.Flags().StringVarP(&catalogSearch, "search", "s", "", "search query (title, album, artist, ...)")
28+
catalogCmd.Flags().StringArrayVarP(&catalogBrands, "brand", "b", []string{}, "brand identifier (1 = Uncaged, 2 = Instinct, 3 = CotW, 4 = Silk, 5 = Silk Showcase)")
29+
catalogCmd.Flags().StringArrayVarP(&catalogGenres, "genre", "g", []string{}, "genre (dubstep, acoustic, ...)")
30+
catalogCmd.Flags().StringArrayVarP(&catalogTypes, "type", "t", []string{}, "release type (Single, EP, Album)")
31+
catalogCmd.Flags().StringArrayVar(&catalogTags, "tag", []string{}, "tags (chill, badass, ...)")
32+
catalogCmd.Flags().BoolVar(&catalogIncludeGold, "gold", true, "include gold releases")
33+
catalogCmd.Flags().BoolVar(&catalogIncludeUnreleased, "unreleased", true, "include unreleased releases")
34+
catalogCmd.Flags().StringVar(&catalogSort, "sort", "-date", "sort by")
2235
catalogCmd.Flags().IntVar(&catalogLimit, "limit", 10, "limit number of catalog")
2336
catalogCmd.Flags().IntVar(&catalogOffset, "offset", 0, "offset number of catalog")
2437

@@ -29,7 +42,37 @@ var catalogCmd = &cobra.Command{
2942
Use: "catalog",
3043
Short: "catalog returns a set of the most recent Monstercat catalog items",
3144
Run: func(cmd *cobra.Command, args []string) {
32-
catalog, err := monstercat.NewClient().Catalog(catalogSearch, catalogType, catalogLimit, catalogOffset)
45+
options := make([]monstercat.BrowseOption, 0)
46+
if catalogSearch != "" {
47+
options = append(options, monstercat.WithSearch(catalogSearch))
48+
}
49+
for _, brand := range catalogBrands {
50+
brandID, err := strconv.Atoi(brand)
51+
if err != nil {
52+
fmt.Printf("%s is not a valid brand id\n", brand)
53+
os.Exit(1)
54+
}
55+
options = append(options, monstercat.WithBrand(brandID))
56+
}
57+
for _, genre := range catalogGenres {
58+
options = append(options, monstercat.WithGenre(genre))
59+
}
60+
for _, releaseType := range catalogTypes {
61+
options = append(options, monstercat.WithReleaseType(releaseType))
62+
}
63+
for _, tag := range catalogTags {
64+
options = append(options, monstercat.WithTag(tag))
65+
}
66+
options = append(
67+
options,
68+
monstercat.IncludeGold(catalogIncludeGold),
69+
monstercat.IncludeUnreleased(catalogIncludeUnreleased),
70+
monstercat.WithSort(catalogSort),
71+
monstercat.WithLimit(catalogLimit),
72+
monstercat.WithOffset(catalogOffset),
73+
)
74+
75+
catalog, err := monstercat.NewClient().BrowseCatalog(options...)
3376
if err != nil {
3477
fmt.Printf("error fetching catalog: %s", err)
3578
os.Exit(1)

0 commit comments

Comments
 (0)