aerc/commands/quit.go

51 lines
871 B
Go
Raw Permalink Normal View History

2019-03-16 01:32:09 +01:00
package commands
import (
"errors"
"fmt"
2019-03-16 01:32:09 +01:00
"git.sr.ht/~rjarry/aerc/commands/mode"
"git.sr.ht/~rjarry/aerc/widgets"
"git.sr.ht/~sircmpwn/getopt"
2019-03-16 01:32:09 +01:00
)
type Quit struct{}
2019-03-16 01:32:09 +01:00
func init() {
register(Quit{})
}
func (Quit) Aliases() []string {
return []string{"quit", "exit"}
}
func (Quit) Complete(aerc *widgets.Aerc, args []string) []string {
return nil
2019-03-16 01:32:09 +01:00
}
type ErrorExit int
func (err ErrorExit) Error() string {
return "exit"
}
func (Quit) Execute(aerc *widgets.Aerc, args []string) error {
force := false
opts, optind, err := getopt.Getopts(args, "f")
if err != nil {
return err
2019-03-16 01:32:09 +01:00
}
for _, opt := range opts {
if opt.Option == 'f' {
force = true
}
}
if len(args) != optind {
return errors.New("Usage: quit [-f]")
}
if force || mode.QuitAllowed() {
return ErrorExit(1)
}
return fmt.Errorf("A task is not done yet. Use -f to force an exit.")
2019-03-16 01:32:09 +01:00
}