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) (core.Configuration, error) {
16 conf := make(core.Configuration)
17
18 projectName, err := promptProjectName()
19 if err != nil {
20 return nil, err
21 }
22
23 conf[keyProject] = projectName
24
25 return conf, nil
26}
27
28func (*Launchpad) ValidateConfig(conf core.Configuration) error {
29 if _, ok := conf[keyProject]; !ok {
30 return fmt.Errorf("missing %s key", keyProject)
31 }
32
33 return nil
34}
35
36func promptProjectName() (string, error) {
37 for {
38 fmt.Print("Launchpad project name: ")
39
40 line, err := bufio.NewReader(os.Stdin).ReadString('\n')
41 if err != nil {
42 return "", err
43 }
44
45 line = strings.TrimRight(line, "\n")
46
47 if line == "" {
48 fmt.Println("Project name is empty")
49 continue
50 }
51
52 return line, nil
53 }
54}