gocollatz/parsing/cliargs.go
Lars M. Rogne 713f70041b
All checks were successful
Run Tests / test (push) Successful in 9s
Clean code improvements.
2024-04-25 04:41:39 +02:00

23 lines
368 B
Go

package parsing
import (
"errors"
"math/big"
"os"
)
type Cliargs struct {
}
func (arg *Cliargs) Parse() (*big.Int, error) {
args := os.Args[1:]
if len(args) != 1 {
return nil, errors.New("only expected 1 arg")
}
num, success := new(big.Int).SetString(args[0], 10)
if !success {
return nil, errors.New("argument is not an integer")
}
return num, nil
}