MCPcopy
hub / github.com/cli/cli / NewOwner

Method NewOwner

pkg/cmd/project/shared/queries/queries.go:1399–1438  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

1397// If login is empty, interactive mode is used to select an owner.
1398// from the current viewer and their organizations
1399func (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

Callers 15

runCloseFunction · 0.80
runLinkFunction · 0.80
runCopyFunction · 0.80
runMarkTemplateFunction · 0.80
runListFunction · 0.80
runDeleteFunction · 0.80
runViewFunction · 0.80
runCreateFieldFunction · 0.80
runDeleteItemFunction · 0.80
runAddItemFunction · 0.80
runListFunction · 0.80
runListFunction · 0.80

Calls 4

OwnerIDAndTypeMethod · 0.95
userOrgLoginsMethod · 0.95
ErrorfMethod · 0.65
SelectMethod · 0.65

Tested by 1

TestNewOwner_nonTTYFunction · 0.64