@@ -71,7 +71,7 @@ func (a *App) Create(ctx context.Context, opts createOptions) error {
7171 return fmt .Errorf ("error getting codespace user: %w" , userResult .Err )
7272 }
7373
74- machine , err := getMachineName (ctx , opts . machine , userResult . User , repository , branch , locationResult .Location , a . apiClient )
74+ machine , err := getMachineName (ctx , a . apiClient , repository . ID , opts . machine , branch , locationResult .Location )
7575 if err != nil {
7676 return fmt .Errorf ("error getting machine type: %w" , err )
7777 }
@@ -234,64 +234,64 @@ func getBranchName(branch string) (string, error) {
234234}
235235
236236// getMachineName prompts the user to select the machine type, or validates the machine if non-empty.
237- func getMachineName (ctx context.Context , machine string , user * api. User , repo * api. Repository , branch , location string , apiClient apiClient ) (string , error ) {
238- skus , err := apiClient .GetCodespacesSKUs (ctx , user , repo , branch , location )
237+ func getMachineName (ctx context.Context , apiClient apiClient , repoID int , machine , branch , location string ) (string , error ) {
238+ machines , err := apiClient .GetCodespacesMachines (ctx , repoID , branch , location )
239239 if err != nil {
240240 return "" , fmt .Errorf ("error requesting machine instance types: %w" , err )
241241 }
242242
243243 // if user supplied a machine type, it must be valid
244244 // if no machine type was supplied, we don't error if there are no machine types for the current repo
245245 if machine != "" {
246- for _ , sku := range skus {
247- if machine == sku .Name {
246+ for _ , m := range machines {
247+ if machine == m .Name {
248248 return machine , nil
249249 }
250250 }
251251
252- availableSKUs := make ([]string , len (skus ))
253- for i := 0 ; i < len (skus ); i ++ {
254- availableSKUs [i ] = skus [i ].Name
252+ availableMachines := make ([]string , len (machines ))
253+ for i := 0 ; i < len (machines ); i ++ {
254+ availableMachines [i ] = machines [i ].Name
255255 }
256256
257- return "" , fmt .Errorf ("there is no such machine for the repository: %s\n Available machines: %v" , machine , availableSKUs )
258- } else if len (skus ) == 0 {
257+ return "" , fmt .Errorf ("there is no such machine for the repository: %s\n Available machines: %v" , machine , availableMachines )
258+ } else if len (machines ) == 0 {
259259 return "" , nil
260260 }
261261
262- if len (skus ) == 1 {
263- return skus [0 ].Name , nil // VS Code does not prompt for SKU if there is only one, this makes us consistent with that behavior
262+ if len (machines ) == 1 {
263+ // VS Code does not prompt for machine if there is only one, this makes us consistent with that behavior
264+ return machines [0 ].Name , nil
264265 }
265266
266- skuNames := make ([]string , 0 , len (skus ))
267- skuByName := make (map [string ]* api.SKU )
268- for _ , sku := range skus {
269- nameParts := camelcase .Split (sku .Name )
267+ machineNames := make ([]string , 0 , len (machines ))
268+ machineByName := make (map [string ]* api.Machine )
269+ for _ , m := range machines {
270+ nameParts := camelcase .Split (m .Name )
270271 machineName := strings .Title (strings .ToLower (nameParts [0 ]))
271- skuName : = fmt .Sprintf ("%s - %s" , machineName , sku .DisplayName )
272- skuNames = append (skuNames , skuName )
273- skuByName [ skuName ] = sku
272+ machineName = fmt .Sprintf ("%s - %s" , machineName , m .DisplayName )
273+ machineNames = append (machineNames , machineName )
274+ machineByName [ machineName ] = m
274275 }
275276
276- skuSurvey := []* survey.Question {
277+ machineSurvey := []* survey.Question {
277278 {
278- Name : "sku " ,
279+ Name : "machine " ,
279280 Prompt : & survey.Select {
280281 Message : "Choose Machine Type:" ,
281- Options : skuNames ,
282- Default : skuNames [0 ],
282+ Options : machineNames ,
283+ Default : machineNames [0 ],
283284 },
284285 Validate : survey .Required ,
285286 },
286287 }
287288
288- var skuAnswers struct { SKU string }
289- if err := ask (skuSurvey , & skuAnswers ); err != nil {
290- return "" , fmt .Errorf ("error getting SKU : %w" , err )
289+ var machineAnswers struct { Machine string }
290+ if err := ask (machineSurvey , & machineAnswers ); err != nil {
291+ return "" , fmt .Errorf ("error getting machine : %w" , err )
291292 }
292293
293- sku := skuByName [skuAnswers .SKU ]
294- machine = sku .Name
294+ selectedMachine := machineByName [machineAnswers .Machine ]
295295
296- return machine , nil
296+ return selectedMachine . Name , nil
297297}
0 commit comments