Skip to content

Commit

Permalink
feat(project): Allow selecting dedicated server
Browse files Browse the repository at this point in the history
  • Loading branch information
pan93412 committed Oct 23, 2024
1 parent 6527b34 commit 3a838a6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
7 changes: 3 additions & 4 deletions internal/cmd/project/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,24 @@ func runCreateInteractive(f *cmdutil.Factory, opts *Options) error {
spinner.WithSuffix(" Fetching available project regions..."),
)
s.Start()
regions, err := f.ApiClient.GetRegions(context.Background())
regions, err := f.ApiClient.GetGenericRegions(context.Background())
if err != nil {
return err
}

regions = regions[1:]
s.Stop()

regionOptions := make([]string, 0, len(regions))
for _, region := range regions {
regionOptions = append(regionOptions, fmt.Sprintf("%s (%s)", region.Description, region.Name))
regionOptions = append(regionOptions, region.String())
}

projectRegionIndex, err := f.Prompter.Select("Select project region", "", regionOptions)
if err != nil {
return err
}

projectRegion := regions[projectRegionIndex].ID
projectRegion := regions[projectRegionIndex].GetID()

s = spinner.New(cmdutil.SpinnerCharSet, cmdutil.SpinnerInterval,
spinner.WithColor(cmdutil.SpinnerColor),
Expand Down
7 changes: 3 additions & 4 deletions pkg/selector/selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,22 @@ func (s *selector) SelectProject(opts ...SelectProjectOptionsApplyer) (zcontext.

if index == len(projects) {

regions, err := s.client.GetRegions(context.Background())
regions, err := s.client.GetGenericRegions(context.Background())
if err != nil {
return nil, nil, fmt.Errorf("get regions failed: %w", err)
}
regions = regions[1:]

regionOptions := make([]string, 0, len(regions))
for _, region := range regions {
regionOptions = append(regionOptions, fmt.Sprintf("%s (%s)", region.Description, region.Name))
regionOptions = append(regionOptions, region.String())
}

projectRegionIndex, err := s.prompter.Select("Select project region", "", regionOptions)
if err != nil {
return nil, nil, fmt.Errorf("select project region failed: %w", err)
}

projectRegion := regions[projectRegionIndex].ID
projectRegion := regions[projectRegionIndex].GetID()

project, err := s.client.CreateProject(context.Background(), projectRegion, nil)
if err != nil {
Expand Down

0 comments on commit 3a838a6

Please sign in to comment.