more flags
This commit is contained in:
parent
76d3221205
commit
eb470f2d17
46
cmd/set.go
46
cmd/set.go
@ -22,14 +22,14 @@ func init() {
|
|||||||
"range",
|
"range",
|
||||||
"r",
|
"r",
|
||||||
"1y",
|
"1y",
|
||||||
"range for setList search (default is 1 Year).",
|
"range for setList search.",
|
||||||
)
|
)
|
||||||
setCmd.PersistentFlags().StringVarP(
|
setCmd.PersistentFlags().StringVarP(
|
||||||
&setPurity,
|
&setPurity,
|
||||||
"purity",
|
"purity",
|
||||||
"p",
|
"p",
|
||||||
"110",
|
"110",
|
||||||
"purity for the setList search (default is 110).",
|
"purity for the setList search.",
|
||||||
)
|
)
|
||||||
setCmd.PersistentFlags().
|
setCmd.PersistentFlags().
|
||||||
StringVarP(
|
StringVarP(
|
||||||
@ -37,7 +37,7 @@ func init() {
|
|||||||
"categories",
|
"categories",
|
||||||
"c",
|
"c",
|
||||||
"010",
|
"010",
|
||||||
"categories for the setList search (default is 010).",
|
"categories for the setList search.",
|
||||||
)
|
)
|
||||||
setCmd.PersistentFlags().
|
setCmd.PersistentFlags().
|
||||||
StringVarP(
|
StringVarP(
|
||||||
@ -45,7 +45,7 @@ func init() {
|
|||||||
"sort",
|
"sort",
|
||||||
"s",
|
"s",
|
||||||
"toplist",
|
"toplist",
|
||||||
"sort by for results, valid sorts: date_added, relevance, random, views, favorites, setlist (default is toplist)",
|
"sort by for results, valid sorts: date_added, relevance, random, views, favorites, setlist.",
|
||||||
)
|
)
|
||||||
setCmd.PersistentFlags().
|
setCmd.PersistentFlags().
|
||||||
StringVarP(
|
StringVarP(
|
||||||
@ -53,7 +53,15 @@ func init() {
|
|||||||
"order",
|
"order",
|
||||||
"o",
|
"o",
|
||||||
"desc",
|
"desc",
|
||||||
"sort order for results, valid sorts: asc desc (default is desc)",
|
"sort order for results, valid sorts: asc desc.",
|
||||||
|
)
|
||||||
|
setCmd.PersistentFlags().
|
||||||
|
IntVarP(
|
||||||
|
&setPage,
|
||||||
|
"maxPage",
|
||||||
|
"m",
|
||||||
|
5,
|
||||||
|
"number of pages to randomly choose wallpaper from.",
|
||||||
)
|
)
|
||||||
setCmd.PersistentFlags().
|
setCmd.PersistentFlags().
|
||||||
BoolVarP(
|
BoolVarP(
|
||||||
@ -61,7 +69,21 @@ func init() {
|
|||||||
"localPath",
|
"localPath",
|
||||||
"l",
|
"l",
|
||||||
false,
|
false,
|
||||||
"set to true if the argument is to a directory or an image file (default is false)",
|
"set if the argument is to a directory or an image file.",
|
||||||
|
)
|
||||||
|
setCmd.PersistentFlags().
|
||||||
|
StringSliceVar(
|
||||||
|
&setRatios,
|
||||||
|
"ratios",
|
||||||
|
[]string{"16x9", "16x10"},
|
||||||
|
"ratios to search for.",
|
||||||
|
)
|
||||||
|
setCmd.PersistentFlags().
|
||||||
|
StringVar(
|
||||||
|
&setAtLeast,
|
||||||
|
"at-least",
|
||||||
|
"2560x1440",
|
||||||
|
"minimum resolution for results.",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,6 +93,9 @@ var (
|
|||||||
setCategories string
|
setCategories string
|
||||||
setSorting string
|
setSorting string
|
||||||
setOrder string
|
setOrder string
|
||||||
|
setAtLeast string
|
||||||
|
setRatios []string
|
||||||
|
setPage int
|
||||||
localPath bool
|
localPath bool
|
||||||
setCmd = &cobra.Command{
|
setCmd = &cobra.Command{
|
||||||
Use: "set",
|
Use: "set",
|
||||||
@ -111,12 +136,9 @@ func set(args []string) error {
|
|||||||
Sorting: setSorting,
|
Sorting: setSorting,
|
||||||
Order: setOrder,
|
Order: setOrder,
|
||||||
TopRange: setRange,
|
TopRange: setRange,
|
||||||
AtLeast: wallhaven.Resolution{Width: 2560, Height: 1440},
|
AtLeast: setAtLeast,
|
||||||
Ratios: []wallhaven.Ratio{
|
Ratios: setRatios,
|
||||||
{Horizontal: 16, Vertical: 9},
|
Page: r.Intn(setPage) + 1,
|
||||||
{Horizontal: 16, Vertical: 10},
|
|
||||||
},
|
|
||||||
Page: r.Intn(5) + 1,
|
|
||||||
}
|
}
|
||||||
log.Println(args)
|
log.Println(args)
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
|
@ -2,7 +2,6 @@ package wallhaven
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -13,107 +12,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Search Types
|
|
||||||
|
|
||||||
// Category is an enum used to represent wallpaper categories
|
|
||||||
type Category string
|
|
||||||
|
|
||||||
// Purity is an enum used to represent
|
|
||||||
type Purity string
|
|
||||||
|
|
||||||
// Sort enum specifies the various sort types accepted by WH api
|
|
||||||
type Sort int
|
|
||||||
|
|
||||||
// Sort Enum Values
|
|
||||||
const (
|
|
||||||
DateAdded Sort = iota + 1
|
|
||||||
Relevance
|
|
||||||
Random
|
|
||||||
Views
|
|
||||||
Favorites
|
|
||||||
Toplist
|
|
||||||
)
|
|
||||||
|
|
||||||
func (s Sort) String() string {
|
|
||||||
str := [...]string{"", "date_added", "relevance", "random", "views", "favorites", "toplist"}
|
|
||||||
return str[s]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Order enum specifies the sort orders accepted by WH api
|
|
||||||
type Order int
|
|
||||||
|
|
||||||
// Sort Enum Values
|
|
||||||
const (
|
|
||||||
Desc Order = iota + 1
|
|
||||||
Asc
|
|
||||||
)
|
|
||||||
|
|
||||||
func (o Order) String() string {
|
|
||||||
str := [...]string{"", "desc", "asc"}
|
|
||||||
return str[o]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Privacy enum specifies the collection privacy returned by WH api
|
|
||||||
type Privacy int
|
|
||||||
|
|
||||||
// Privacy Enum Values
|
|
||||||
const (
|
|
||||||
Private Privacy = iota
|
|
||||||
Public
|
|
||||||
)
|
|
||||||
|
|
||||||
func (p Privacy) String() string {
|
|
||||||
str := [...]string{"private", "public"}
|
|
||||||
return str[p]
|
|
||||||
}
|
|
||||||
|
|
||||||
// TopRange is used to specify the time window for 'top' result when topList is chosen as sort param
|
|
||||||
type TopRange int
|
|
||||||
|
|
||||||
// Enum for TopRange values
|
|
||||||
const (
|
|
||||||
Day TopRange = iota + 1
|
|
||||||
ThreeDay
|
|
||||||
Week
|
|
||||||
Month
|
|
||||||
ThreeMonth
|
|
||||||
SixMonth
|
|
||||||
Year
|
|
||||||
)
|
|
||||||
|
|
||||||
func (t TopRange) String() string {
|
|
||||||
str := [...]string{"1d", "3d", "1w", "1M", "3M", "6M", "1y"}
|
|
||||||
return str[t]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resolution specifies the image resolution to find
|
|
||||||
type Resolution struct {
|
|
||||||
Width int64
|
|
||||||
Height int64
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r Resolution) String() string {
|
|
||||||
return fmt.Sprintf("%vx%v", r.Width, r.Height)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r Resolution) isValid() bool {
|
|
||||||
return r.Width > 0 && r.Height > 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ratio may be used to specify the aspect ratio of the search
|
|
||||||
type Ratio struct {
|
|
||||||
Horizontal int
|
|
||||||
Vertical int
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r Ratio) String() string {
|
|
||||||
return fmt.Sprintf("%vx%v", r.Horizontal, r.Vertical)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r Ratio) isValid() bool {
|
|
||||||
return r.Vertical > 0 && r.Horizontal > 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// WallpaperID is a string representing a wallpaper
|
// WallpaperID is a string representing a wallpaper
|
||||||
type WallpaperID string
|
type WallpaperID string
|
||||||
|
|
||||||
@ -161,9 +59,9 @@ type Search struct {
|
|||||||
Sorting string
|
Sorting string
|
||||||
Order string
|
Order string
|
||||||
TopRange string
|
TopRange string
|
||||||
AtLeast Resolution
|
AtLeast string
|
||||||
Resolutions []Resolution
|
Resolutions []string
|
||||||
Ratios []Ratio
|
Ratios []string
|
||||||
Colors []string // Colors is an array of hex colors represented as strings in #RRGGBB format
|
Colors []string // Colors is an array of hex colors represented as strings in #RRGGBB format
|
||||||
Page int
|
Page int
|
||||||
}
|
}
|
||||||
@ -185,30 +83,14 @@ func (s Search) toQuery() url.Values {
|
|||||||
if s.TopRange != "" && s.Sorting == "toplist" {
|
if s.TopRange != "" && s.Sorting == "toplist" {
|
||||||
v.Add("topRange", s.TopRange)
|
v.Add("topRange", s.TopRange)
|
||||||
}
|
}
|
||||||
if s.AtLeast.isValid() {
|
if s.AtLeast != "" {
|
||||||
v.Add("atleast", s.AtLeast.String())
|
v.Add("atleast", s.AtLeast)
|
||||||
}
|
}
|
||||||
if len(s.Resolutions) > 0 {
|
if len(s.Resolutions) > 0 {
|
||||||
outRes := []string{}
|
v.Add("resolutions", strings.Join(s.Ratios, ","))
|
||||||
for _, res := range s.Resolutions {
|
|
||||||
if res.isValid() {
|
|
||||||
outRes = append(outRes, res.String())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(outRes) > 0 {
|
|
||||||
v.Add("resolutions", strings.Join(outRes, ","))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if len(s.Ratios) > 0 {
|
if len(s.Ratios) > 0 {
|
||||||
outRat := []string{}
|
v.Add("ratios", strings.Join(s.Ratios, ","))
|
||||||
for _, rat := range s.Ratios {
|
|
||||||
if rat.isValid() {
|
|
||||||
outRat = append(outRat, rat.String())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(outRat) > 0 {
|
|
||||||
v.Add("ratios", strings.Join(outRat, ","))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if len(s.Colors) > 0 {
|
if len(s.Colors) > 0 {
|
||||||
v.Add("colors", strings.Join([]string(s.Colors), ","))
|
v.Add("colors", strings.Join([]string(s.Colors), ","))
|
||||||
|
Loading…
Reference in New Issue
Block a user