2019-06-10 01:21:26 +02:00
|
|
|
package account
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2019-09-20 18:16:29 +02:00
|
|
|
"strings"
|
2020-05-28 16:32:32 +02:00
|
|
|
"time"
|
2019-06-10 01:21:26 +02:00
|
|
|
|
2021-11-05 10:19:46 +01:00
|
|
|
"git.sr.ht/~rjarry/aerc/widgets"
|
|
|
|
"git.sr.ht/~rjarry/aerc/worker/types"
|
2019-06-10 01:21:26 +02:00
|
|
|
)
|
|
|
|
|
2019-06-27 19:33:11 +02:00
|
|
|
type MakeDir struct{}
|
|
|
|
|
2019-06-10 01:21:26 +02:00
|
|
|
func init() {
|
2019-06-27 19:33:11 +02:00
|
|
|
register(MakeDir{})
|
|
|
|
}
|
|
|
|
|
2019-09-03 21:34:03 +02:00
|
|
|
func (MakeDir) Aliases() []string {
|
2019-06-27 19:33:11 +02:00
|
|
|
return []string{"mkdir"}
|
|
|
|
}
|
|
|
|
|
2019-09-03 21:34:03 +02:00
|
|
|
func (MakeDir) Complete(aerc *widgets.Aerc, args []string) []string {
|
2019-06-27 19:33:11 +02:00
|
|
|
return nil
|
2019-06-10 01:21:26 +02:00
|
|
|
}
|
|
|
|
|
2019-09-03 21:34:03 +02:00
|
|
|
func (MakeDir) Execute(aerc *widgets.Aerc, args []string) error {
|
2019-09-20 18:16:29 +02:00
|
|
|
if len(args) == 0 {
|
2019-06-10 01:21:26 +02:00
|
|
|
return errors.New("Usage: :mkdir <name>")
|
|
|
|
}
|
|
|
|
acct := aerc.SelectedAccount()
|
|
|
|
if acct == nil {
|
|
|
|
return errors.New("No account selected")
|
|
|
|
}
|
2019-09-20 18:16:29 +02:00
|
|
|
name := strings.Join(args[1:], " ")
|
2019-06-10 01:21:26 +02:00
|
|
|
acct.Worker().PostAction(&types.CreateDirectory{
|
|
|
|
Directory: name,
|
|
|
|
}, func(msg types.WorkerMessage) {
|
|
|
|
switch msg := msg.(type) {
|
|
|
|
case *types.Done:
|
2020-05-28 16:32:32 +02:00
|
|
|
aerc.PushStatus("Directory created.", 10*time.Second)
|
2019-06-10 01:21:26 +02:00
|
|
|
acct.Directories().Select(name)
|
|
|
|
case *types.Error:
|
2021-01-30 13:51:32 +01:00
|
|
|
aerc.PushError(msg.Error.Error())
|
2019-06-10 01:21:26 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
return nil
|
|
|
|
}
|