aboutsummaryrefslogtreecommitdiffstats
path: root/commands/patch/init.go
blob: de0c6e45d499125774396e074eba6b34cfeb8f1f (plain) (blame)
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
package patch

import (
	"fmt"
	"os"
	"path/filepath"

	"git.sr.ht/~rjarry/aerc/commands"
	"git.sr.ht/~rjarry/aerc/lib/pama"
)

type Init struct {
	Force bool   `opt:"-f"`
	Name  string `opt:"name" required:"false"`
}

func init() {
	register(Init{})
}

func (Init) Context() commands.CommandContext {
	return commands.GLOBAL
}

func (Init) Aliases() []string {
	return []string{"init"}
}

func (i Init) Execute(args []string) error {
	cwd, err := os.Getwd()
	if err != nil {
		return fmt.Errorf("Could not get current directory: %w", err)
	}

	name := i.Name
	if name == "" {
		name = filepath.Base(cwd)
	}

	return pama.New().Init(name, cwd, i.Force)
}