From bc176bd61ba726351a489cabf4da16a47dc5ec3b Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Tue, 10 Oct 2023 00:08:31 +0200 Subject: 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 Acked-by: Moritz Poldrack --- commands/exec.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'commands/exec.go') diff --git a/commands/exec.go b/commands/exec.go index a38c8789..a34f54e7 100644 --- a/commands/exec.go +++ b/commands/exec.go @@ -21,11 +21,11 @@ func (ExecCmd) Aliases() []string { return []string{"exec"} } -func (ExecCmd) Complete(aerc *app.Aerc, args []string) []string { +func (ExecCmd) Complete(args []string) []string { return nil } -func (ExecCmd) Execute(aerc *app.Aerc, args []string) error { +func (ExecCmd) Execute(args []string) error { if len(args) < 2 { return errors.New("Usage: exec [cmd...]") } @@ -33,7 +33,7 @@ func (ExecCmd) Execute(aerc *app.Aerc, args []string) error { cmd := exec.Command(args[1], args[2:]...) env := os.Environ() - switch view := aerc.SelectedTabContent().(type) { + switch view := app.SelectedTabContent().(type) { case *app.AccountView: env = append(env, fmt.Sprintf("account=%s", view.AccountConfig().Name)) env = append(env, fmt.Sprintf("folder=%s", view.Directories().Selected())) @@ -50,14 +50,14 @@ func (ExecCmd) Execute(aerc *app.Aerc, args []string) error { err := cmd.Run() if err != nil { - aerc.PushError(err.Error()) + app.PushError(err.Error()) } else { if cmd.ProcessState.ExitCode() != 0 { - aerc.PushError(fmt.Sprintf( + app.PushError(fmt.Sprintf( "%s: completed with status %d", args[0], cmd.ProcessState.ExitCode())) } else { - aerc.PushStatus(fmt.Sprintf( + app.PushStatus(fmt.Sprintf( "%s: completed with status %d", args[0], cmd.ProcessState.ExitCode()), 10*time.Second) } -- cgit