Skip to content

Commit

Permalink
create first project stage when running the deploy command
Browse files Browse the repository at this point in the history
  • Loading branch information
djelusic committed Dec 17, 2021
1 parent fa1ff8a commit 942c01f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
5 changes: 1 addition & 4 deletions cli/cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,13 +469,10 @@ func newDeployCommand() *cobra.Command {
Long: texts.Deploy.Long,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
d, err := controller.NewDeploy(a)
err := controller.NewDeploy(a)
if err != nil {
return log.Wrap(err)
}
if err := d.Deploy(); err != nil {
return log.Wrap(err)
}
showNextSteps(texts.Deploy.NextSteps)
return nil
},
Expand Down
28 changes: 24 additions & 4 deletions cli/controller/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,32 @@ type Deploy struct {
updateDuration time.Duration
}

func NewDeploy(a DeployArgs) (*Deploy, error) {
fs, stage, err := newStoreWithStage(a.Stage)
func NewDeploy(a DeployArgs) error {
fs, _, err := newProjectStore()
if err != nil {
return nil, log.Wrap(err)
return log.Wrap(err)
}
return NewDeployWithStage(fs, stage)
stage := fs.Stage(a.Stage)
if stage == nil {
return createStage(a.Stage)
}
d, err := NewDeployWithStage(fs, stage)
if err != nil {
return log.Wrap(err)
}
return d.Deploy()
}

func createStage(name string) error {
ui.Info("\nNo stages found for this project, creating a new stage...")
s, err := NewStage(StageArgs{
Stage: name,
})
if err != nil {
return log.Wrap(err)
}
_, err = s.New()
return err
}

func NewDeployWithStage(fs *domain.FileStore, stage *domain.Stage) (*Deploy, error) {
Expand Down
6 changes: 5 additions & 1 deletion cli/controller/stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ func (s *Stage) New() (bool, error) {

func (s *Stage) chooseCreateStage() (*domain.Stage, error) {
stageName := s.Stage
if stageName == "" {
stageName, _ = promptStageName()
}
for {
stage, err := s.project.NewStage(stageName, s.Node, s.store.ProjectRoot())
var see *domain.StageExistsError
Expand All @@ -116,7 +119,8 @@ func (s *Stage) chooseCreateStage() (*domain.Stage, error) {

func promptStageName() (string, error) {
prompt := promptui.Prompt{
Label: "Please specify a new stage name to continue",
Label: "Please specify a new stage name to continue",
Default: domain.DefaultStageName,
}
stage, err := prompt.Run()
return stage, err
Expand Down

0 comments on commit 942c01f

Please sign in to comment.