aboutsummaryrefslogtreecommitdiffstats
path: root/commands/quit.go
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2022-07-11 20:23:41 +0200
committerRobin Jarry <robin@jarry.cc>2022-07-14 23:15:02 +0200
commite200cd56bf22ec48d1b0441be2355dc6dcb35cd4 (patch)
treebc7b5bce028281fdf11bcfbdb5db221f8fa4d27a /commands/quit.go
parent5102d32ceabf4292a4af7d528f7ba5f070183518 (diff)
downloadaerc-e200cd56bf22ec48d1b0441be2355dc6dcb35cd4.tar.gz
commands: implement a no-quit mode
Add a mode that prevents aerc from quitting normally when an important task is performed, i.e. when sending a message. The no-quit mode will be ignored when quit is used with the -f option to force an exit. Suggested-by: ph14nix[m] Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'commands/quit.go')
-rw-r--r--commands/quit.go23
1 files changed, 20 insertions, 3 deletions
diff --git a/commands/quit.go b/commands/quit.go
index fbec2b7d..ee5f46c1 100644
--- a/commands/quit.go
+++ b/commands/quit.go
@@ -2,8 +2,11 @@ package commands
import (
"errors"
+ "fmt"
+ "git.sr.ht/~rjarry/aerc/commands/mode"
"git.sr.ht/~rjarry/aerc/widgets"
+ "git.sr.ht/~sircmpwn/getopt"
)
type Quit struct{}
@@ -27,8 +30,22 @@ func (err ErrorExit) Error() string {
}
func (Quit) Execute(aerc *widgets.Aerc, args []string) error {
- if len(args) != 1 {
- return errors.New("Usage: quit")
+ force := false
+ opts, optind, err := getopt.Getopts(args, "f")
+ if err != nil {
+ return err
}
- return ErrorExit(1)
+ for _, opt := range opts {
+ switch opt.Option {
+ case '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.")
}