gocollatz/parsing/cliargs.go

29 lines
465 B
Go
Raw Permalink Normal View History

2024-04-24 20:04:34 +00:00
package parsing
2024-04-24 17:49:03 +00:00
import (
"errors"
"math/big"
"os"
)
type Cliargs struct {
value *big.Int
}
2024-04-24 17:53:00 +00:00
func (arg *Cliargs) Parse() (*big.Int, error) {
2024-04-24 17:49:03 +00:00
args := os.Args[1:]
if len(args) != 1 {
2024-04-24 17:53:00 +00:00
return nil, errors.New("only expected 1 arg")
2024-04-24 17:49:03 +00:00
}
num, success := new(big.Int).SetString(args[0], 10)
if !success {
2024-04-24 17:53:00 +00:00
return nil, errors.New("argument is not an integer")
2024-04-24 17:49:03 +00:00
}
arg.value = num
2024-04-24 17:53:00 +00:00
return num, nil
2024-04-24 17:49:03 +00:00
}
func (arg *Cliargs) GetNumber() *big.Int {
return arg.value
}