get-options.go (427B)
1 package xkcd 2 3 import ( 4 "fmt" 5 "strconv" 6 ) 7 8 // Option is of the type `xkcd action [num]'. 9 // Return (action, num, err) -- err, if any. 10 func GetOption(args []string) (option string, num int, err error) { 11 if len(args) > 1 { 12 option = args[1] 13 } 14 if len(args) > 2 { 15 maybenum, e := strconv.Atoi(args[2]) 16 if e != nil { 17 err = fmt.Errorf("Please specify a valid number.\n") 18 } 19 num = maybenum 20 } 21 return option, num, err 22 }