package main import ( "flag" "fmt" "strconv" "strings" "git.sr.ht/~kisom/goutils/die" ) var barWeight = 45 func parsePlates(plates string) int { halfWeight := 0 plateValues := strings.Split(plates, ",") for i := range plateValues { plateValues[i] = strings.TrimSpace(plateValues[i]) weight, err := strconv.Atoi(plateValues[i]) die.If(err) halfWeight += weight } return halfWeight } func totalWeight(halfWeight int) { totalWeight := (2 * halfWeight) + barWeight fmt.Printf("Total weight: %d#\n", totalWeight) } func main() { flag.IntVar(&barWeight, "b", barWeight, "bar weight") nPlates := flag.Int("n", 0, "number of plates") plateWeight := flag.Int("p", 45, "plate weight") flag.Parse() if *nPlates != 0 { totalWeight(*nPlates * *plateWeight) } else { totalWeight(parsePlates(strings.Join(flag.Args(), ","))) } }