mirror of
https://git.sr.ht/~rjarry/aerc
synced 2025-07-02 22:00:21 +02:00

Update the Command interface to include a Description() method. Implement the method for all commands using short descriptions inspired from the aerc(1) man page. Return the description values along with command names so that they can be displayed in completion choices. Implements: https://todo.sr.ht/~rjarry/aerc/271 Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Bojan Gabric <bojan@bojangabric.com> Tested-by: Jason Cox <me@jasoncarloscox.com> Acked-by: Tim Culverhouse <tim@timculverhouse.com>
51 lines
832 B
Go
51 lines
832 B
Go
package patch
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"time"
|
|
|
|
"git.sr.ht/~rjarry/aerc/app"
|
|
"git.sr.ht/~rjarry/aerc/commands"
|
|
"git.sr.ht/~rjarry/aerc/lib/pama"
|
|
)
|
|
|
|
type Cd struct{}
|
|
|
|
func init() {
|
|
register(Cd{})
|
|
}
|
|
|
|
func (Cd) Description() string {
|
|
return "Change aerc's working directory to the current project."
|
|
}
|
|
|
|
func (Cd) Context() commands.CommandContext {
|
|
return commands.GLOBAL
|
|
}
|
|
|
|
func (Cd) Aliases() []string {
|
|
return []string{"cd"}
|
|
}
|
|
|
|
func (Cd) Execute(args []string) error {
|
|
p, err := pama.New().CurrentProject()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
cwd, err := os.Getwd()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if cwd == p.Root {
|
|
app.PushStatus("Already here.", 10*time.Second)
|
|
return nil
|
|
}
|
|
err = os.Chdir(p.Root)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
app.PushStatus(fmt.Sprintf("Changed to %s.", p.Root),
|
|
10*time.Second)
|
|
return nil
|
|
}
|