summary refs log tree commit diff stats
path: root/doc/examples
Commit message (Expand)AuthorAgeFilesLines
* Added redrawing when we return to Vim from Ranger without opening anyAshwin Nanjappa2014-09-191-0/+2
* examples/vim_file_chooser: fixed redrawinghut2014-02-151-0/+1
* Update vim_file_chooser.vimIsrael Chauca Fuentes2013-09-171-11/+27
* update examples (s/ranger.fsobject/ranger.container/)hut2013-03-172-5/+5
* move examples to doc/exampleshut2013-03-0911-0/+200
id='n69' href='#n69'>69
package commands

import (
	"errors"
	"strings"

	"git.sr.ht/~sircmpwn/aerc/widgets"

	"github.com/go-ini/ini"
)

type Set struct{}

func setUsage() string {
	return "set <category>.<option> <value>"
}

func init() {
	register(Set{})
}

func (Set) Aliases() []string {
	return []string{"set"}

}

func (Set) Complete(aerc *widgets.Aerc, args []string) []string {
	return nil
}

func SetCore(aerc *widgets.Aerc, args []string) error {
	if len(args) != 3 {
		return errors.New("Usage: " + setUsage())
	}

	config := aerc.Config()

	parameters := strings.Split(args[1], ".")

	if len(parameters) != 2 {
		return errors.New("Usage: " + setUsage())
	}

	category := parameters[0]
	option := parameters[1]
	value := args[2]

	new_file := ini.Empty()

	section, err := new_file.NewSection(category)

	if err != nil {
		return nil
	}

	if _, err := section.NewKey(option, value); err != nil {
		return err
	}

	if err := config.LoadConfig(new_file); err != nil {
		return err
	}

	return nil
}

func (Set) Execute(aerc *widgets.Aerc, args []string) error {
	return SetCore(aerc, args)
}