MCPcopy Create free account
hub / github.com/OctopusDeploy/cli / deleteRun

Function deleteRun

pkg/cmd/user/delete/delete.go:64–103  ·  view source on GitHub ↗
(opts *DeleteOptions)

Source from the content-addressed store, hash-verified

62}
63
64func deleteRun(opts *DeleteOptions) error {
65 if !opts.NoPrompt {
66 if err := PromptMissing(opts); err != nil {
67 return err
68 }
69 }
70
71 if opts.UsernameOrId == "" {
72 return fmt.Errorf("user identifier is required but was not provided")
73 }
74
75 // first we find by username
76 // filter is not an exact match so it might find more than one row, but unlikely to find more than 2
77 candidates, err := opts.Client.Users.Get(users.UsersQuery{Filter: opts.UsernameOrId, Take: 9999})
78 if err != nil {
79 return err
80 }
81
82 var itemToDelete *users.User = nil
83 for _, candidate := range candidates.Items {
84 if strings.EqualFold(opts.UsernameOrId, candidate.Username) {
85 itemToDelete = candidate
86 break
87 }
88 }
89 if itemToDelete == nil { // couldn't match by username, try Id
90 itemToDelete, err = opts.Client.Users.GetByID(opts.UsernameOrId)
91 if err != nil {
92 return err // can't find a user to delete. Give up
93 }
94 }
95
96 if opts.Confirm.Value {
97 return deleteUser(opts.Client, itemToDelete)
98 } else {
99 return question.DeleteWithConfirmation(opts.Ask, "user", itemToDelete.DisplayName, itemToDelete.ID, func() error {
100 return deleteUser(opts.Client, itemToDelete)
101 })
102 }
103}
104
105func PromptMissing(opts *DeleteOptions) error {
106 if opts.UsernameOrId == "" {

Callers 1

NewCmdDeleteFunction · 0.70

Calls 4

DeleteWithConfirmationFunction · 0.92
deleteUserFunction · 0.85
PromptMissingFunction · 0.70
GetMethod · 0.65

Tested by

no test coverage detected