MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / newOrganizationLeaveCmd

Function newOrganizationLeaveCmd

app/cli/cmd/organization_leave.go:42–82  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

40}
41
42func newOrganizationLeaveCmd() *cobra.Command {
43 var orgName string
44 cmd := &cobra.Command{
45 Use: "leave",
46 Short: "leave an organization",
47 RunE: func(cmd *cobra.Command, args []string) error {
48 ctx := cmd.Context()
49 // To find the membership ID, we need to iterate and filter by org
50 membership, err := membershipFromOrg(ctx, orgName)
51 if err != nil {
52 return fmt.Errorf("getting membership: %w", err)
53 } else if membership == nil {
54 return fmt.Errorf("organization %s not found", orgName)
55 }
56
57 fmt.Printf("You are about to leave the organization %q\n", membership.Org.Name)
58
59 // Ask for confirmation
60 if err := confirmDeletion(); err != nil {
61 return err
62 }
63
64 // Membership deletion
65 if err := action.NewMembershipLeave(ActionOpts).Run(ctx, membership.ID); err != nil {
66 return fmt.Errorf("deleting membership: %w", err)
67 }
68
69 // set the local state
70 if err := setLocalOrganization(""); err != nil {
71 return fmt.Errorf("writing config file: %w", err)
72 }
73
74 logger.Info().Msg("Membership deleted")
75 return nil
76 },
77 }
78
79 cmd.Flags().StringVar(&orgName, "name", "", "organization name")
80 cobra.CheckErr(cmd.MarkFlagRequired("name"))
81 return cmd
82}

Callers 1

newOrganizationCmdFunction · 0.85

Calls 7

NewMembershipLeaveFunction · 0.92
membershipFromOrgFunction · 0.85
confirmDeletionFunction · 0.85
setLocalOrganizationFunction · 0.85
ContextMethod · 0.80
InfoMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected