NewOwner creates a project Owner If canPrompt is false, login is required as we cannot prompt for it. If login is not empty, it is used to lookup the project owner. If login is empty, interactive mode is used to select an owner. from the current viewer and their organizations
(canPrompt bool, login string)
| 1397 | // If login is empty, interactive mode is used to select an owner. |
| 1398 | // from the current viewer and their organizations |
| 1399 | func (c *Client) NewOwner(canPrompt bool, login string) (*Owner, error) { |
| 1400 | if login != "" { |
| 1401 | id, ownerType, err := c.OwnerIDAndType(login) |
| 1402 | if err != nil { |
| 1403 | return nil, err |
| 1404 | } |
| 1405 | |
| 1406 | return &Owner{ |
| 1407 | Login: login, |
| 1408 | Type: ownerType, |
| 1409 | ID: id, |
| 1410 | }, nil |
| 1411 | } |
| 1412 | |
| 1413 | if !canPrompt { |
| 1414 | return nil, fmt.Errorf("owner is required when not running interactively") |
| 1415 | } |
| 1416 | |
| 1417 | logins, err := c.userOrgLogins() |
| 1418 | if err != nil { |
| 1419 | return nil, err |
| 1420 | } |
| 1421 | |
| 1422 | options := make([]string, 0, len(logins)) |
| 1423 | for _, l := range logins { |
| 1424 | options = append(options, l.Login) |
| 1425 | } |
| 1426 | |
| 1427 | answerIndex, err := c.prompter.Select("Which owner would you like to use?", "", options) |
| 1428 | if err != nil { |
| 1429 | return nil, err |
| 1430 | } |
| 1431 | |
| 1432 | l := logins[answerIndex] |
| 1433 | return &Owner{ |
| 1434 | Login: l.Login, |
| 1435 | Type: l.Type, |
| 1436 | ID: l.ID, |
| 1437 | }, nil |
| 1438 | } |
| 1439 | |
| 1440 | // NewProject creates a project based on the owner and project number |
| 1441 | // if canPrompt is false, number is required as we cannot prompt for it |