Debian Codegraph @

commands/move-tab.go

raw
1 package commands
2
3 import (
4 "strconv"
5 "strings"
6
7 "git.sr.ht/~rjarry/aerc/app"
8 )
9
10 type MoveTab struct {
11 Index int `opt:"index" minus:"true" metavar:"[+|-]<index>" action:"ParseIndex"`
12 Relative bool
13 }
14
15 func init() {
16 Register(MoveTab{})
17 }
18
19 func (MoveTab) Description() string {
20 return "Move the selected tab to the given index."
21 }
22
23 func (MoveTab) Context() CommandContext {
24 return GLOBAL
25 }
26
27 func (m *MoveTab) ParseIndex(arg string) error {
28 i, err := strconv.ParseInt(arg, 10, 64)
29 if err != nil {
30 return err
31 }
32 m.Index = int(i)
33 if strings.HasPrefix(arg, "+") || strings.HasPrefix(arg, "-") {
34 m.Relative = true
35 }
36 return nil
37 }
38
39 func (MoveTab) Aliases() []string {
40 return []string{"move-tab"}
41 }
42
43 func (m MoveTab) Execute(args []string) error {
44 app.MoveTab(m.Index, m.Relative)
45 return nil
46 }