Skip to content

Commit

Permalink
project create / create should not start linked sandbox #536
Browse files Browse the repository at this point in the history
  • Loading branch information
pmi authored and alansemenov committed May 8, 2024
1 parent 55aa0e3 commit e270447
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 18 deletions.
6 changes: 4 additions & 2 deletions internal/app/commands/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ var Create = cli.Command{
},
Action: func(c *cli.Context) error {

project := project.ProjectCreateWizard(c, true)
project, newBox := project.ProjectCreateWizard(c, true)

sandbox.AskToStartSandbox(c, project.Sandbox)
if newBox {
sandbox.AskToStartSandbox(c, project.Sandbox)
}

return nil
},
Expand Down
2 changes: 1 addition & 1 deletion internal/app/commands/project/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var Build = cli.Command{
}

func buildProject(c *cli.Context) {
if projectData := ensureProjectDataExists(c, ".", "", "A sandbox is required for your project, create one"); projectData != nil {
if projectData, _ := ensureProjectDataExists(c, ".", "", "A sandbox is required for your project, create one"); projectData != nil {
var buildMessage string
if sandbox.Exists(projectData.Sandbox) {
buildMessage = fmt.Sprintf("Building in sandbox '%s'...", projectData.Sandbox)
Expand Down
3 changes: 2 additions & 1 deletion internal/app/commands/project/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ var Clean = cli.Command{
Usage: "Clean current project",
Flags: []cli.Flag{common.FORCE_FLAG},
Action: func(c *cli.Context) error {
if projectData := ensureProjectDataExists(c, ".", "", "A sandbox is required to clean the project, do you want to create one"); projectData != nil {
if projectData, _ := ensureProjectDataExists(c, ".", "", "A sandbox is required to clean the project, "+
"do you want to create one"); projectData != nil {
var cleanMessage string
if sandbox.Exists(projectData.Sandbox) {
cleanMessage = fmt.Sprintf("Cleaning in sandbox '%s'...", projectData.Sandbox)
Expand Down
13 changes: 7 additions & 6 deletions internal/app/commands/project/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,16 @@ var Create = cli.Command{
},
Action: func(c *cli.Context) error {

project := ProjectCreateWizard(c, false)

sandbox.AskToStartSandbox(c, project.Sandbox)
project, newBox := ProjectCreateWizard(c, false)

if newBox {
sandbox.AskToStartSandbox(c, project.Sandbox)
}
return nil
},
}

func ProjectCreateWizard(c *cli.Context, simplified bool) *common.ProjectData {
func ProjectCreateWizard(c *cli.Context, simplified bool) (*common.ProjectData, bool) {
fmt.Fprint(os.Stderr, "\n")

branch := c.String("branch")
Expand Down Expand Up @@ -167,7 +168,7 @@ func ProjectCreateWizard(c *cli.Context, simplified bool) *common.ProjectData {
util.Fatal(err, "Error creating project")

sandboxName := c.String("sandbox")
pData := ensureProjectDataExists(c, dest, sandboxName, "A sandbox is required for your project, create one")
pData, newBox := ensureProjectDataExists(c, dest, sandboxName, "A sandbox is required for your project, create one")

if pData == nil || pData.Sandbox == "" {
fmt.Fprintf(os.Stdout, "\nProject created in '%s'\n", absDest)
Expand All @@ -194,7 +195,7 @@ func ProjectCreateWizard(c *cli.Context, simplified bool) *common.ProjectData {

fmt.Fprintf(os.Stderr, util.FormatImportant("cd %s\nenonic dev\n\n"), dest)

return pData
return pData, newBox
}

func ensureVersion(c *cli.Context, version string) string {
Expand Down
3 changes: 2 additions & 1 deletion internal/app/commands/project/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ var Deploy = cli.Command{
if c.NArg() > 0 {
sandboxName = c.Args().First()
}
if projectData := ensureProjectDataExists(c, ".", sandboxName, "A sandbox is required to deploy the project, do you want to create one"); projectData != nil {
if projectData, _ := ensureProjectDataExists(c, ".", sandboxName, "A sandbox is required to deploy the project, "+
"do you want to create one"); projectData != nil {
sandboxExists := sandbox.Exists(projectData.Sandbox)
tasks := []string{"deploy"}
if continuous {
Expand Down
3 changes: 2 additions & 1 deletion internal/app/commands/project/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ var Dev = cli.Command{
}

func StartDevMode(c *cli.Context) {
if projectData := ensureProjectDataExists(c, ".", "", "A sandbox is required to run the project in dev mode, do you want to create one"); projectData != nil {
if projectData, _ := ensureProjectDataExists(c, ".", "", "A sandbox is required to run the project in dev mode, "+
"do you want to create one"); projectData != nil {

sbox := sandbox.ReadSandboxFromProjectOrAsk(c, false)

Expand Down
3 changes: 2 additions & 1 deletion internal/app/commands/project/gradle.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ var Gradle = cli.Command{
tasks = append(tasks, arg)
}

if projectData := ensureProjectDataExists(c, ".", "", "A sandbox is required to run gradle in the project, do you want to create one"); projectData != nil {
if projectData, _ := ensureProjectDataExists(c, ".", "", "A sandbox is required to run gradle in the project, "+
"do you want to create one"); projectData != nil {
var gradleMessage string
if sandbox.Exists(projectData.Sandbox) {
gradleMessage = fmt.Sprintf("Running gradle %v in sandbox '%s'...", tasks, projectData.Sandbox)
Expand Down
8 changes: 4 additions & 4 deletions internal/app/commands/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func ensureValidProjectFolder(prjPath string) {
}
}

func ensureProjectDataExists(c *cli.Context, prjPath, sandboxName, noBoxMessage string) *common.ProjectData {
func ensureProjectDataExists(c *cli.Context, prjPath, sandboxName, noBoxMessage string) (*common.ProjectData, bool) {
var newBox bool
var sBox *sandbox.Sandbox

Expand All @@ -74,7 +74,7 @@ func ensureProjectDataExists(c *cli.Context, prjPath, sandboxName, noBoxMessage

if force && badSandbox && sandboxName == "" {
// allow project without a sandbox in force mode
return projectData
return projectData, newBox
} else if badSandbox || sandboxName != "" {
sBox, newBox = sandbox.EnsureSandboxExists(c, sandbox.EnsureSandboxOptions{
MinDistroVersion: minDistroVersion,
Expand All @@ -84,7 +84,7 @@ func ensureProjectDataExists(c *cli.Context, prjPath, sandboxName, noBoxMessage
ShowCreateOption: true,
})
if sBox == nil {
return nil
return nil, newBox
}
projectData.Sandbox = sBox.Name
if badSandbox {
Expand All @@ -107,7 +107,7 @@ func ensureProjectDataExists(c *cli.Context, prjPath, sandboxName, noBoxMessage
}
}

return projectData
return projectData, newBox
}

func runGradleTask(projectData *common.ProjectData, message string, tasks ...string) {
Expand Down
3 changes: 2 additions & 1 deletion internal/app/commands/project/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ var Test = cli.Command{
Usage: "Run tests in the current project",
Flags: []cli.Flag{common.FORCE_FLAG},
Action: func(c *cli.Context) error {
if projectData := ensureProjectDataExists(c, ".", "", "A sandbox is required to test the project, do you want to create one"); projectData != nil {
if projectData, _ := ensureProjectDataExists(c, ".", "", "A sandbox is required to test the project, "+
"do you want to create one"); projectData != nil {
var cleanMessage string
if sandbox.Exists(projectData.Sandbox) {
cleanMessage = fmt.Sprintf("Testing in sandbox '%s'...", projectData.Sandbox)
Expand Down

0 comments on commit e270447

Please sign in to comment.