diff --git a/collatz/calculator.go b/collatz/calculator.go index 7be8fb4..5756d2c 100644 --- a/collatz/calculator.go +++ b/collatz/calculator.go @@ -25,11 +25,10 @@ func NewCalculator(parser *io.Cliargs) Calculator { } func (o Calculator) Collatz() { - err := o.parser.Parse() + number, err := o.parser.Parse() if err != nil { log.Panicf("Couldn't parse input: %s\n", err) } - number := o.parser.GetNumber() fmt.Print(number.Text(10)) o.nextNumber(number) fmt.Println() diff --git a/io/cliargs.go b/io/cliargs.go index f396516..f89abe5 100644 --- a/io/cliargs.go +++ b/io/cliargs.go @@ -10,17 +10,17 @@ type Cliargs struct { value *big.Int } -func (arg *Cliargs) Parse() error { +func (arg *Cliargs) Parse() (*big.Int, error) { args := os.Args[1:] if len(args) != 1 { - return errors.New("only expected 1 arg") + return nil, errors.New("only expected 1 arg") } num, success := new(big.Int).SetString(args[0], 10) if !success { - return errors.New("argument is not an integer") + return nil, errors.New("argument is not an integer") } arg.value = num - return nil + return num, nil } func (arg *Cliargs) GetNumber() *big.Int {