gocollatz/io/cliargs.go

29 lines
460 B
Go
Raw Normal View History

2024-04-24 17:49:03 +00:00
package io
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
}