aerc/commands/account/next-folder.go

54 lines
949 B
Go
Raw Normal View History

2019-03-21 20:30:23 +00:00
package account
2019-03-11 01:15:24 +00:00
import (
2019-03-11 01:23:22 +00:00
"errors"
"fmt"
"strconv"
"git.sr.ht/~rjarry/aerc/widgets"
2019-03-11 01:15:24 +00:00
)
type NextPrevFolder struct{}
2019-03-11 01:15:24 +00:00
func init() {
register(NextPrevFolder{})
2019-03-11 01:23:22 +00:00
}
func (NextPrevFolder) Aliases() []string {
return []string{"next-folder", "prev-folder"}
}
func (NextPrevFolder) Complete(aerc *widgets.Aerc, args []string) []string {
return nil
2019-03-11 01:15:24 +00:00
}
func (NextPrevFolder) Execute(aerc *widgets.Aerc, args []string) error {
2019-03-11 01:23:22 +00:00
if len(args) > 2 {
2019-03-15 03:41:25 +00:00
return nextPrevFolderUsage(args[0])
2019-03-11 01:23:22 +00:00
}
var (
n int = 1
err error
)
if len(args) > 1 {
n, err = strconv.Atoi(args[1])
if err != nil {
2019-03-15 03:41:25 +00:00
return nextPrevFolderUsage(args[0])
2019-03-11 01:23:22 +00:00
}
}
2019-03-11 01:15:24 +00:00
acct := aerc.SelectedAccount()
if acct == nil {
return errors.New("No account selected")
}
if args[0] == "prev-folder" {
acct.Directories().NextPrev(-n)
} else {
acct.Directories().NextPrev(n)
2019-03-11 01:23:22 +00:00
}
2019-03-11 01:15:24 +00:00
return nil
}
func nextPrevFolderUsage(cmd string) error {
return fmt.Errorf("Usage: %s [n]", cmd)
}