summary refs log tree commit diff stats
path: root/nimpretty
Commit message (Expand)AuthorAgeFilesLines
...
* nimpretty: fixes #9506Andreas Rumpf2018-10-263-1/+15
* nimpretty: fixes #9500Araq2018-10-252-0/+46
* nimpretty: fixes #9504Araq2018-10-252-0/+10
* nimpretty: closes #9484Araq2018-10-242-0/+18
* nimpretty: test for idempotence; fixes #9483Araq2018-10-243-6/+24
* nimpretty: fixes #8078Araq2018-10-242-0/+16
* nimpretty: fixes #9398Araq2018-10-243-1/+14
* closes #9400Araq2018-10-232-0/+10
* nimpretty: minor bug fixAraq2018-10-232-0/+2
* nimpretty: fixes #9384Araq2018-10-171-1/+1
* nimpretty: added an new simple testAndreas Rumpf2018-10-162-0/+6
* nimpretty: fixes #9144Andreas Rumpf2018-10-162-0/+9
* nimpretty: add #!nimpretty on/off directivesAndreas Rumpf2018-10-162-4/+20
* nimpretty: fixes #8626Andreas Rumpf2018-10-163-1/+18
* nimpretty: render r-strings properly, fixes #9236Andreas Rumpf2018-10-162-0/+4
* make tests green againAraq2018-09-071-3/+3
* nimpretty: detect '; vs ,' style based on the first usage of the token in par...Araq2018-06-261-1/+1
* nimpretty: bugfixes; refs #8078Araq2018-06-203-1/+35
* nimpretty: added more code claimed to not be workingAndreas Rumpf2018-06-202-0/+26
* nimpretty: fixes more reported issuesAndreas Rumpf2018-06-202-0/+6
* nimpretty: don't produce trailing whitespace; fixes the rendering of unary op...Andreas Rumpf2018-06-192-7/+7
* nimpretty: proper command line handling; added tests; travis ensures these st...Andreas Rumpf2018-06-195-0/+681
n' href='/akspecs/aerc/blame/commands/commands.go?h=0.4.0&id=62862d8a9e7f684bc3ff4e9ea115678ff44d8644'>^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50




                

                                 


                                           
                                                              
 
                                    
 




















                                                              

 
                                                                            






                                                        
                                               
                                     
         
                                     
 
package commands

import (
	"errors"

	"github.com/google/shlex"

	"git.sr.ht/~sircmpwn/aerc2/widgets"
)

type AercCommand func(aerc *widgets.Aerc, args []string) error

type Commands map[string]AercCommand

func NewCommands() *Commands {
	cmds := Commands(make(map[string]AercCommand))
	return &cmds
}

func (cmds *Commands) dict() map[string]AercCommand {
	return map[string]AercCommand(*cmds)
}

func (cmds *Commands) Register(name string, cmd AercCommand) {
	cmds.dict()[name] = cmd
}

type NoSuchCommand string

func (err NoSuchCommand) Error() string {
	return "Unknown command " + string(err)
}

type CommandSource interface {
	Commands() *Commands
}

func (cmds *Commands) ExecuteCommand(aerc *widgets.Aerc, cmd string) error {
	args, err := shlex.Split(cmd)
	if err != nil {
		return err
	}
	if len(args) == 0 {
		return errors.New("Expected a command.")
	}
	if fn, ok := cmds.dict()[args[0]]; ok {
		return fn(aerc, args)
	}
	return NoSuchCommand(args[0])
}