diff options
Diffstat (limited to 'command.go')
| -rw-r--r-- | command.go | 40 |
1 files changed, 36 insertions, 4 deletions
@@ -43,11 +43,35 @@ func ParseCommand(line string) (*Command, error) { } case 'b': if strings.HasPrefix("back", cmd) { - return &Command{Name: "back"}, nil + fields := strings.Fields(rest) + switch len(fields) { + case 0: + return &Command{Name: "back"}, nil + case 1: + if _, err := strconv.Atoi(fields[0]); err != nil { + return nil, ErrInvalidArgs + } + return &Command{Name: "back", Args: fields}, nil + default: + return nil, ErrInvalidArgs + + } } case 'f': if strings.HasPrefix("forward", cmd) { - return &Command{Name: "forward"}, nil + fields := strings.Fields(rest) + switch len(fields) { + case 0: + return &Command{Name: "forward"}, nil + case 1: + if _, err := strconv.Atoi(fields[0]); err != nil { + return nil, ErrInvalidArgs + } + return &Command{Name: "forward", Args: fields}, nil + default: + return nil, ErrInvalidArgs + + } } case 'n': if strings.HasPrefix("next", cmd) { @@ -270,9 +294,17 @@ func RunCommand(conf *Config, cmd *Command, state *BrowserState) error { case "reload": return Reload(state, conf) case "back": - return Back(state) + num := 1 + if len(cmd.Args) == 1 { + num, _ = strconv.Atoi(cmd.Args[0]) + } + return Back(state, num) case "forward": - return Forward(state) + num := 1 + if len(cmd.Args) == 1 { + num, _ = strconv.Atoi(cmd.Args[0]) + } + return Forward(state, num) case "next": return Next(state, conf) case "previous": |
