mirror of
https://github.com/onyx-and-iris/lottery-cli.git
synced 2026-08-17 00:34:25 +00:00
move lottery draw logic into runLottery() move MarkFlagsMutuallyExclusive into init()
42 lines
808 B
Go
42 lines
808 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
// validateNonPromptCount checks if the count is valid when the count-prompt flag is not set.
|
|
func validateNonPromptCount() error {
|
|
if viper.GetBool("count-prompt") {
|
|
return nil
|
|
}
|
|
|
|
return validateCount(viper.GetInt("count"))
|
|
}
|
|
|
|
// validateCount checks if the count is valid.
|
|
func validateCount(count int) error {
|
|
if count < 1 {
|
|
return fmt.Errorf("count must be greater than 0")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// parseCount parses the count from a string and validates it.
|
|
func parseCount(raw string) (int, error) {
|
|
count, err := strconv.Atoi(strings.TrimSpace(raw))
|
|
if err != nil {
|
|
return 0, fmt.Errorf("count must be a whole number")
|
|
}
|
|
|
|
if err := validateCount(count); err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
return count, nil
|
|
}
|