Improve argument parsing

This commit is contained in:
Gabriel Augendre 2021-08-23 13:13:51 +02:00
parent 48beae409c
commit 58028d59ea
1 changed files with 6 additions and 6 deletions

12
main.go
View File

@ -79,13 +79,13 @@ func IsPrime(n int) bool {
return true
}
func parseArgs() (int, int, int, int) {
start := flag.Int("start", 0, "The start number")
max := flag.Int("max", 10_000, "The end value")
step := flag.Int("step-size", 1_000, "The job size")
func parseArgs() (start, max, step, printCount int) {
flag.IntVar(&start, "start", 0, "The start number")
flag.IntVar(&max, "max", 10_000, "The end value")
flag.IntVar(&step, "step-size", 1_000, "The job size")
printCountDesc := `Number of primes to print. -1 to print all.
Primes are not guaranteed to be sorted.`
printCount := flag.Int("print-count", 20, printCountDesc)
flag.IntVar(&printCount, "print-count", 20, printCountDesc)
flag.Parse()
return *start, *max, *step, *printCount
return
}