MCPcopy Create free account
hub / github.com/openclaw/gogcli / Run

Method Run

internal/cmd/admin_groups.go:209–261  ·  view source on GitHub ↗
(ctx context.Context, flags *RootFlags)

Source from the content-addressed store, hash-verified

207}
208
209func (c *AdminGroupsMembersAddCmd) Run(ctx context.Context, flags *RootFlags) error {
210 u := ui.FromContext(ctx)
211 groupEmail := strings.TrimSpace(c.GroupEmail)
212 memberEmail := strings.TrimSpace(c.MemberEmail)
213 if groupEmail == "" || memberEmail == "" {
214 return usage("group email and member email required")
215 }
216 if err := validatePlainEmail("member email", memberEmail); err != nil {
217 return err
218 }
219
220 role := strings.ToUpper(c.Role)
221 if role != adminRoleMember && role != adminRoleManager && role != adminRoleOwner {
222 return usage("role must be MEMBER, MANAGER, or OWNER")
223 }
224
225 member := &admin.Member{
226 Email: memberEmail,
227 Role: role,
228 }
229
230 if dryRunErr := dryRunExit(ctx, flags, "admin.groups.members.add", map[string]any{
231 "group": groupEmail,
232 "member": member,
233 }); dryRunErr != nil {
234 return dryRunErr
235 }
236
237 account, err := requireAdminAccount(flags)
238 if err != nil {
239 return err
240 }
241
242 svc, err := adminDirectoryService(ctx, account)
243 if err != nil {
244 return wrapAdminDirectoryError(err, account)
245 }
246
247 created, err := svc.Members.Insert(groupEmail, member).Context(ctx).Do()
248 if err != nil {
249 return wrapAdminDirectoryError(err, account)
250 }
251
252 if outfmt.IsJSON(ctx) {
253 return outfmt.WriteJSON(ctx, stdoutWriter(ctx), map[string]any{
254 "email": created.Email,
255 "role": created.Role,
256 })
257 }
258
259 u.Out().Linef("Added %s to %s as %s", created.Email, groupEmail, created.Role)
260 return nil
261}
262
263type AdminGroupsMembersRemoveCmd struct {
264 GroupEmail string `arg:"" name:"groupEmail" help:"Group email"`

Callers

nothing calls this directly

Calls 13

FromContextFunction · 0.92
IsJSONFunction · 0.92
WriteJSONFunction · 0.92
usageFunction · 0.85
validatePlainEmailFunction · 0.85
dryRunExitFunction · 0.85
requireAdminAccountFunction · 0.85
adminDirectoryServiceFunction · 0.85
wrapAdminDirectoryErrorFunction · 0.85
stdoutWriterFunction · 0.85
LinefMethod · 0.80
OutMethod · 0.80

Tested by

no test coverage detected