/
python.go
66 lines (63 loc) · 1.86 KB
/
python.go
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Package python contains PythonCmd which generates new python project using template.
package python
import (
"github.com/armour/jarvis/internal/pkg/config"
"github.com/armour/jarvis/internal/pkg/utils"
"github.com/spf13/cobra"
survey "gopkg.in/AlecAivazis/survey.v1"
)
var questions = []*survey.Question{
{
Name: "projectName",
Prompt: &survey.Input{
Message: "Project name?",
Default: "my-project",
Help: "The name of the new project.",
},
Validate: survey.Required,
},
{
Name: "projectDescription",
Prompt: &survey.Input{
Message: "Project Description?",
Help: "The description of the new project.",
},
Validate: survey.Required,
},
{
Name: "license",
Prompt: &survey.Select{
Message: "Choose a license:",
Options: []string{"MIT", "GPL", "Apache"},
Default: "MIT",
},
Validate: survey.Required,
},
}
// PythonCmd generates new python project using template.
var PythonCmd = &cobra.Command{
Use: "python",
Short: "Start a new project using 'python' template",
Long: "Start a new project using 'python' template",
Run: func(cmd *cobra.Command, args []string) {
answers := struct {
License string
ProjectDescription string
ProjectName string
}{}
if err := survey.Ask(questions, &answers); err != nil {
utils.ExitOnError(err)
}
templates := []string{"new/python", "new/github", "new/license"}
requireMap := map[string]interface{}{}
replaceMap := map[string]interface{}{
"author": config.GetConfigByField("author"),
"email": config.GetConfigByField("email"),
"githubUser": config.GetConfigByField("githubUser"),
"license": answers.License,
"projectDescription": answers.ProjectDescription,
"projectName": answers.ProjectName,
}
utils.GenerateFile(templates, answers.ProjectName, requireMap, replaceMap)
},
}