Debian Codegraph @

commands/quit.go

raw
1 package commands
2
3 import (
4 "fmt"
5
6 "git.sr.ht/~rjarry/aerc/commands/mode"
7 )
8
9 type Quit struct {
10 Force bool `opt:"-f" desc:"Force quit even if a task is pending."`
11 }
12
13 func init() {
14 Register(Quit{})
15 }
16
17 func (Quit) Description() string {
18 return "Exit aerc."
19 }
20
21 func (Quit) Context() CommandContext {
22 return GLOBAL
23 }
24
25 func (Quit) Aliases() []string {
26 return []string{"quit", "q", "exit"}
27 }
28
29 type ErrorExit int
30
31 func (err ErrorExit) Error() string {
32 return "exit"
33 }
34
35 func (q Quit) Execute(args []string) error {
36 if q.Force || mode.QuitAllowed() {
37 return ErrorExit(1)
38 }
39 return fmt.Errorf("A task is not done yet. Use -f to force an exit.")
40 }