2018-12-08 05:58:51 +03:00
|
|
|
package launchpad
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/MichaelMure/git-bug/bridge/core"
|
|
|
|
"github.com/MichaelMure/git-bug/repository"
|
|
|
|
)
|
|
|
|
|
|
|
|
const keyProject = "project"
|
|
|
|
|
|
|
|
func (*Launchpad) Configure(repo repository.RepoCommon) (core.Configuration, error) {
|
|
|
|
conf := make(core.Configuration)
|
|
|
|
|
|
|
|
projectName, err := promptProjectName()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
conf[keyProject] = projectName
|
|
|
|
|
|
|
|
return conf, nil
|
|
|
|
}
|
|
|
|
|
2018-12-17 15:05:05 +03:00
|
|
|
func (*Launchpad) ValidateConfig(conf core.Configuration) error {
|
|
|
|
if _, ok := conf[keyProject]; !ok {
|
|
|
|
return fmt.Errorf("missing %s key", keyProject)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-12-08 05:58:51 +03:00
|
|
|
func promptProjectName() (string, error) {
|
|
|
|
for {
|
|
|
|
fmt.Print("Launchpad project name: ")
|
|
|
|
|
|
|
|
line, err := bufio.NewReader(os.Stdin).ReadString('\n')
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
line = strings.TrimRight(line, "\n")
|
|
|
|
|
|
|
|
if line == "" {
|
|
|
|
fmt.Println("Project name is empty")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
return line, nil
|
|
|
|
}
|
|
|
|
}
|