config.go

 1package launchpad
 2
 3import (
 4	"bufio"
 5	"fmt"
 6	"os"
 7	"strings"
 8
 9	"github.com/MichaelMure/git-bug/bridge/core"
10	"github.com/MichaelMure/git-bug/repository"
11)
12
13const keyProject = "project"
14
15func (*Launchpad) Configure(repo repository.RepoCommon, params core.BridgeParams) (core.Configuration, error) {
16	conf := make(core.Configuration)
17
18	if params.Project == "" {
19		projectName, err := promptProjectName()
20		if err != nil {
21			return nil, err
22		}
23
24		conf[keyProject] = projectName
25	}
26
27	return conf, nil
28}
29
30func (*Launchpad) ValidateConfig(conf core.Configuration) error {
31	if _, ok := conf[keyProject]; !ok {
32		return fmt.Errorf("missing %s key", keyProject)
33	}
34
35	return nil
36}
37
38func promptProjectName() (string, error) {
39	for {
40		fmt.Print("Launchpad project name: ")
41
42		line, err := bufio.NewReader(os.Stdin).ReadString('\n')
43		if err != nil {
44			return "", err
45		}
46
47		line = strings.TrimRight(line, "\n")
48
49		if line == "" {
50			fmt.Println("Project name is empty")
51			continue
52		}
53
54		return line, nil
55	}
56}
57
58func validateProject() (bool, error) {
59	return false, nil
60}