Skip to content

Commit

Permalink
Improve prequisite handling, print all fails instead of the first only
Browse files Browse the repository at this point in the history
  • Loading branch information
marevers committed Nov 14, 2024
1 parent 05927f1 commit ddf30be
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions pleasant/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,38 +35,39 @@ import (
"gopkg.in/yaml.v3"
)

type prerequisite struct {
type Prerequisite struct {
Message string
PrerequisiteMet bool
}

func CheckPrerequisites(prereq ...*prerequisite) bool {
func CheckPrerequisites(prereq ...*Prerequisite) bool {
eCount := 0

for _, p := range prereq {
if !p.PrerequisiteMet {
fmt.Println(p.Message)

return false
eCount++
}
}

return true
return eCount <= 0
}

func IsTokenValid() *prerequisite {
func IsTokenValid() *Prerequisite {
b := time.Now().Unix() <= viper.GetInt64("bearertoken.expiresat")

pr := &prerequisite{
pr := &Prerequisite{
Message: "Token is expired or not present. Please log in (again) with 'pleasant-cli login'.",
PrerequisiteMet: b,
}

return pr
}

func IsServerUrlSet() *prerequisite {
func IsServerUrlSet() *Prerequisite {
b := (viper.IsSet("serverurl") && viper.GetString("serverurl") != "")

pr := &prerequisite{
pr := &Prerequisite{
Message: "Server URL is not set. Please set it with 'pleasant-cli config serverurl <SERVER URL>'.",
PrerequisiteMet: b,
}
Expand Down

0 comments on commit ddf30be

Please sign in to comment.