Skip to content

Commit

Permalink
feat: create project with context set
Browse files Browse the repository at this point in the history
  • Loading branch information
qiaoborui committed Oct 31, 2023
1 parent 6b551d0 commit b1fd05b
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion internal/cmd/project/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package create
import (
"context"
"fmt"
"github.com/zeabur/cli/pkg/zcontext"

"github.com/briandowns/spinner"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -103,7 +104,11 @@ func createProject(f *cmdutil.Factory, projectRegion string, projectName *string
}

f.Log.Infof("Project %s created", project.Name)

err = setProject(f, project.ID, project.Name)
if err != nil {
f.Log.Error(err)
return err
}
return nil
}

Expand All @@ -114,3 +119,18 @@ func paramCheck(opts *Options) error {

return nil
}

func setProject(f *cmdutil.Factory, id, name string) error {
if id == "" && name == "" {
return fmt.Errorf("context auto-switching failed, check if the project was created successfully")
}
f.Config.GetContext().SetProject(zcontext.NewBasicInfo(id, name))

// clear environment and service context when project context is set
f.Config.GetContext().ClearService()
f.Config.GetContext().ClearEnvironment()

f.Log.Infof("Project context is set to <%s>", name)

return nil
}

0 comments on commit b1fd05b

Please sign in to comment.