aboutsummaryrefslogtreecommitdiffstats
path: root/commands/account/import-mbox.go
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-10-10 00:08:31 +0200
committerRobin Jarry <robin@jarry.cc>2023-10-10 11:38:01 +0200
commitbc176bd61ba726351a489cabf4da16a47dc5ec3b (patch)
treebbf06f731592d072f3d6f76f1648d61989375f2e /commands/account/import-mbox.go
parent598e4a5803578ab3e291f232d6aad31b4efd8ea4 (diff)
downloadaerc-bc176bd61ba726351a489cabf4da16a47dc5ec3b.tar.gz
app: export global functions
The single Aerc object is passed around in almost all command functions. This hinders readability. Store the single Aerc instance as a global variable. Export public functions from the app package to access methods of that object. Remove all explicit references to *app.Aerc and replace them with calls to these functions. For references to private/unexported fields and functions from within the app package, directly access the global aerc object. Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Moritz Poldrack <moritz@poldrack.dev>
Diffstat (limited to 'commands/account/import-mbox.go')
-rw-r--r--commands/account/import-mbox.go23
1 files changed, 11 insertions, 12 deletions
diff --git a/commands/account/import-mbox.go b/commands/account/import-mbox.go
index 2a441737..4ede8c26 100644
--- a/commands/account/import-mbox.go
+++ b/commands/account/import-mbox.go
@@ -28,17 +28,17 @@ func (ImportMbox) Aliases() []string {
return []string{"import-mbox"}
}
-func (ImportMbox) Complete(aerc *app.Aerc, args []string) []string {
+func (ImportMbox) Complete(args []string) []string {
return commands.CompletePath(filepath.Join(args...))
}
-func (ImportMbox) Execute(aerc *app.Aerc, args []string) error {
+func (ImportMbox) Execute(args []string) error {
if len(args) != 2 {
return importFolderUsage(args[0])
}
filename := args[1]
- acct := aerc.SelectedAccount()
+ acct := app.SelectedAccount()
if acct == nil {
return errors.New("No account selected")
}
@@ -55,18 +55,18 @@ func (ImportMbox) Execute(aerc *app.Aerc, args []string) error {
importFolder := func() {
defer log.PanicHandler()
statusInfo := fmt.Sprintln("Importing", filename, "to folder", folder)
- aerc.PushStatus(statusInfo, 10*time.Second)
+ app.PushStatus(statusInfo, 10*time.Second)
log.Debugf(statusInfo)
f, err := os.Open(filename)
if err != nil {
- aerc.PushError(err.Error())
+ app.PushError(err.Error())
return
}
defer f.Close()
messages, err := mboxer.Read(f)
if err != nil {
- aerc.PushError(err.Error())
+ app.PushError(err.Error())
return
}
worker := acct.Worker()
@@ -94,7 +94,7 @@ func (ImportMbox) Execute(aerc *app.Aerc, args []string) error {
case *types.Unsupported:
errMsg := fmt.Sprintf("%s: AppendMessage is unsupported", args[0])
log.Errorf(errMsg)
- aerc.PushError(errMsg)
+ app.PushError(errMsg)
return
case *types.Error:
log.Errorf("AppendMessage failed: %v", msg.Error)
@@ -125,23 +125,22 @@ func (ImportMbox) Execute(aerc *app.Aerc, args []string) error {
}
infoStr := fmt.Sprintf("%s: imported %d of %d successfully.", args[0], appended, len(messages))
log.Debugf(infoStr)
- aerc.PushSuccess(infoStr)
+ app.PushSuccess(infoStr)
}
if len(store.Uids()) > 0 {
confirm := app.NewSelectorDialog(
"Selected directory is not empty",
fmt.Sprintf("Import mbox file to %s anyways?", folder),
- []string{"No", "Yes"}, 0, aerc.SelectedAccountUiConfig(),
+ []string{"No", "Yes"}, 0, app.SelectedAccountUiConfig(),
func(option string, err error) {
- aerc.CloseDialog()
- aerc.Invalidate()
+ app.CloseDialog()
if option == "Yes" {
go importFolder()
}
},
)
- aerc.AddDialog(confirm)
+ app.AddDialog(confirm)
} else {
go importFolder()
}