Skip to content

Commit

Permalink
add columns and flags for acceleRATE and positions information in `pl…
Browse files Browse the repository at this point in the history
…ayers` command
  • Loading branch information
matheusfm committed Oct 11, 2022
1 parent ef85b4b commit bef52a5
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 25 deletions.
2 changes: 1 addition & 1 deletion cmd/latest.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var latestCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
p, err := playersClient.Latest()
cobra.CheckErr(err)
printPlayers(p)
printPlayers(p, false, false)
},
}

Expand Down
28 changes: 21 additions & 7 deletions cmd/players.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/dustin/go-humanize"
"github.com/fatih/color"
"github.com/matheusfm/futbin/nations"
"github.com/matheusfm/futbin/players"
"github.com/spf13/cobra"
)
Expand All @@ -20,6 +19,7 @@ var (
flagNationID int
flagLeagueID int
flagPosition []string
flagAccelerate string
flagPrice string
flagWeakFoot string
flagSkills string
Expand Down Expand Up @@ -73,7 +73,9 @@ var playersCmd = &cobra.Command{
4. # Icons with a maximum price of 300K:
futbin players --league 2118 --price -300000

This comment has been minimized.

Copy link
@Abdou678sj

Abdou678sj Aug 20, 2024

Merci beaucoup

5. # Players with 5 weak foot and 5 skills:
futbin players --wf 5 --skills 5`,
futbin players --wf 5 --skills 5
6. # Players with Lengthy AcceleRATE:
futbin players --accelerate=lengthy`,
Run: func(cmd *cobra.Command, args []string) {
p, err := playersClient.Get(&players.Options{
Platform: platform,
Expand All @@ -83,6 +85,7 @@ var playersCmd = &cobra.Command{
NationID: flagNationID,
LeagueID: flagLeagueID,
Position: flagPosition,
Accelerate: flagAccelerate,
Price: flagToRange(flagPrice),
WeakFoot: flagToRange(flagWeakFoot),
Skills: flagToRange(flagSkills),
Expand Down Expand Up @@ -123,7 +126,7 @@ var playersCmd = &cobra.Command{
Aggression: flagToRange(flagAggression),
})
cobra.CheckErr(err)
printPlayers(p)
printPlayers(p, true, true)
},
}

Expand All @@ -139,6 +142,7 @@ func init() {
playersCmd.PersistentFlags().StringVar(&flagRating, "ovr", "", "Rating")
playersCmd.PersistentFlags().StringVar(&flagPrice, "price", "", "Price")
playersCmd.PersistentFlags().StringSliceVar(&flagPosition, "position", []string{}, "Position")
playersCmd.PersistentFlags().StringVar(&flagAccelerate, "accelerate", "", "Accelerate")
playersCmd.PersistentFlags().StringVar(&flagPace, "pace", "", "Pace")
playersCmd.PersistentFlags().StringVar(&flagAcceleration, "acceleration", "", "Acceleration")
playersCmd.PersistentFlags().StringVar(&flagSprintSpeed, "sprint-speed", "", "Sprint Speed")
Expand Down Expand Up @@ -175,7 +179,11 @@ func init() {
playersCmd.PersistentFlags().StringVar(&flagAggression, "aggression", "", "Aggression")
}

func printPlayers(p []players.Player) {
func printPlayers(p []players.Player, accelerate, allPositions bool) {
a := "ACCELERATE"
if !accelerate {
a = ""
}
header := []string{
"ID",
"NAME",
Expand All @@ -184,6 +192,7 @@ func printPlayers(p []players.Player) {
"NATION (ID)",
"LEAGUE (ID)",
"POS",
a,
fmt.Sprintf("PRICE (%s)", platform),
"PAC",
"SHO",
Expand All @@ -194,14 +203,19 @@ func printPlayers(p []players.Player) {
}
data := make([][]string, len(p))
for i, player := range p {
pos := player.MainPosition
if allPositions {
pos = player.Positions
}
data[i] = []string{
strconv.Itoa(player.ID),
player.CommonName,
strconv.Itoa(player.Rating),
fmt.Sprintf("%s (%d)", player.ClubName, player.ClubID),
fmt.Sprintf("%s (%d)", nations.Nations[player.NationID], player.NationID),
fmt.Sprintf("%s (%d)", player.Club, player.ClubID),
fmt.Sprintf("%s (%d)", player.Nation, player.NationID),
fmt.Sprintf("%s (%d)", player.League, player.LeagueID),
player.Position,
pos,
player.Accelerate,
color.HiYellowString(humanize.Comma(int64(player.Price(platform)))),
colorStat(player.Pace),
colorStat(player.Shooting),
Expand Down
2 changes: 1 addition & 1 deletion cmd/popular.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var popularCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
p, err := playersClient.Popular()
cobra.CheckErr(err)
printPlayers(p)
printPlayers(p, false, false)
},
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/totw.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var totwCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
p, err := playersClient.TOTW()
cobra.CheckErr(err)
printPlayers(p)
printPlayers(p, false, false)
},
}

Expand Down
23 changes: 12 additions & 11 deletions players/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@ type Options struct {

Version string

Position []string
NationID int
LeagueID int
ClubID int
Height string
Weight string
WeakFoot Range
Skills Range
Foot Foot
Rating Range
Price Range
Position []string
Accelerate string
NationID int
LeagueID int
ClubID int
Height string
Weight string
WeakFoot Range
Skills Range
Foot Foot
Rating Range
Price Range

Pace Range
Acceleration Range
Expand Down
12 changes: 8 additions & 4 deletions players/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ type Player struct {
Name string `json:"playername"`
CommonName string `json:"common_name"`

Position string `json:"position"`
Rating int `json:"rating"`
RareType int `json:"raretype"`
MainPosition string `json:"position"`
Positions string `json:"pos_all"`
Accelerate string `json:"accelerate"`

Rating int `json:"rating"`
RareType int `json:"raretype"`

Pace int `json:"pac"`
Shooting int `json:"sho"`
Expand All @@ -21,7 +24,8 @@ type Player struct {
Physicality int `json:"phy"`

ClubID int `json:"club"`
ClubName string `json:"club_name"`
Club string `json:"club_name"`
Nation string `json:"nation_name"`
NationID int `json:"nation"`
LeagueID int `json:"league"`
League string `json:"league_name"`
Expand Down
2 changes: 2 additions & 0 deletions players/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type playerQuery struct {
Version string `url:"version,omitempty"`

Position []string `url:"position,comma,omitempty"`
Accelerate string `url:"accelerate,omitempty"`
NationID int `url:"nation,omitempty"`
LeagueID int `url:"league,omitempty"`
ClubID int `url:"club,omitempty"`
Expand Down Expand Up @@ -74,6 +75,7 @@ func newPlayerQuery(opt *Options) *playerQuery {
Order: opt.Order,
Version: opt.Version,
Position: opt.Position,
Accelerate: opt.Accelerate,
NationID: opt.NationID,
LeagueID: opt.LeagueID,
ClubID: opt.ClubID,
Expand Down

0 comments on commit bef52a5

Please sign in to comment.