-
Notifications
You must be signed in to change notification settings - Fork 785
/
create_project.go
152 lines (133 loc) · 3.85 KB
/
create_project.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package cmd
import (
"fmt"
"os"
"github.com/jenkins-x/jx/pkg/jx/cmd/templates"
"github.com/jenkins-x/jx/pkg/util"
"github.com/spf13/cobra"
)
const (
createQuickstartName = "Create new application from a Quickstart"
createCamelName = "Create new Apache Camel microservice"
createSpringName = "Create new Spring Boot microservice"
importDirName = "Import existing code from a directory"
importGitName = "Import code from a git repository"
importGitHubName = "Import code from a github repository"
)
var (
createProjectNames = []string{
createQuickstartName,
createCamelName,
createSpringName,
importDirName,
importGitName,
importGitHubName,
}
createProjectLong = templates.LongDesc(`
Create a new Project by importing code, using a Quickstart or custom wizard for Spring or Camel.
` + SeeAlsoText("jx create quickstart", "jx create spring", "jx create camel", "jx create jhipster", "jx import"))
createProjectExample = templates.Examples(`
# Create a project
jx create project
`)
)
// CreateProjectWizardOptions the options for the command
type CreateProjectWizardOptions struct {
CreateOptions
}
// NewCmdCreateProject creates a command object for the "create" command
func NewCmdCreateProject(commonOpts *CommonOptions) *cobra.Command {
options := &CreateProjectWizardOptions{
CreateOptions: CreateOptions{
CommonOptions: commonOpts,
},
}
cmd := &cobra.Command{
Use: "project",
Short: "Create a new Project by importing code, using a Quickstart or custom wizard for Spring or Camel",
Long: createProjectLong,
Example: createProjectExample,
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
err := options.Run()
CheckErr(err)
},
}
return cmd
}
// Run implements the command
func (o *CreateProjectWizardOptions) Run() error {
name, err := util.PickName(createProjectNames, "Which kind of project you want to create: ",
"Jenkins X supports a number of diffferent wizards for creating or importing new projects.",
o.In, o.Out, o.Err)
if err != nil {
return err
}
switch name {
case createCamelName:
return o.createCamel()
case createQuickstartName:
return o.createQuickstart()
case createSpringName:
return o.createSpring()
case importDirName:
return o.importDir()
case importGitName:
return o.importGit()
case importGitHubName:
return o.importGithubProject()
default:
return fmt.Errorf("Unknown selection: %s\n", name)
}
}
func (o *CreateProjectWizardOptions) createCamel() error {
w := &CreateCamelOptions{}
w.CommonOptions = o.CommonOptions
return w.Run()
}
func (o *CreateProjectWizardOptions) createQuickstart() error {
w := &CreateQuickstartOptions{}
w.CommonOptions = o.CommonOptions
return w.Run()
}
func (o *CreateProjectWizardOptions) createSpring() error {
w := &CreateSpringOptions{}
w.CommonOptions = o.CommonOptions
return w.Run()
}
func (o *CreateProjectWizardOptions) importDir() error {
wd, err := os.Getwd()
if err != nil {
return err
}
dir, err := util.PickValue("Which directory contains the source code: ", wd, true,
"Please specify the directory which contains the source code you want to use for your new project", o.In, o.Out, o.Err)
if err != nil {
return err
}
w := &ImportOptions{
Dir: dir,
}
w.CommonOptions = o.CommonOptions
return w.Run()
}
func (o *CreateProjectWizardOptions) importGit() error {
repoUrl, err := util.PickValue("Which git repository URL to inmport: ", "", true,
"Please specify the git URL which contains the source code you want to use for your new project", o.In, o.Out, o.Err)
if err != nil {
return err
}
w := &ImportOptions{
RepoURL: repoUrl,
}
w.CommonOptions = o.CommonOptions
return w.Run()
}
func (o *CreateProjectWizardOptions) importGithubProject() error {
w := &ImportOptions{
GitHub: true,
}
w.CommonOptions = o.CommonOptions
return w.Run()
}