original_docstring: 
      Leave a group in which you are a member.
  
      If multiple identities in your identity set are members, all memberships will be
      removed by default. If needed, use the `--identity` flag to control this behavior.
  
      You may not leave a group in which you are the last remaining `admin` user.
      
docstring: Leave a group in which you are a member.
  If multiple identities in your identity set are members, all memberships will be
  removed by default. If needed, use the `--identity` flag to control this behavior.
  
  You may not leave a group in which you are the last remaining `admin` user.
docstring_tokens: Leave a group in which you are a member . If multiple identities in your identity set are members all memberships will be removed by default . If needed use the ` -- identity ` flag to control this behavior . You may not leave a group in which you are the last remaining ` admin ` user .
code: def group_leave(
      *,
      group_id: uuid.UUID,
      identity: Optional[ParsedIdentity],
      login_manager: LoginManager,
  ):
      """
      Leave a group in which you are a member.
  
      If multiple identities in your identity set are members, all memberships will be
      removed by default. If needed, use the `--identity` flag to control this behavior.
  
      You may not leave a group in which you are the last remaining `admin` user.
      """
      auth_client = login_manager.get_auth_client()
      groups_client = login_manager.get_groups_client()
  
      if identity:
          identity_id = auth_client.maybe_lookup_identity_id(identity.value)
          if not identity_id:
              raise click.UsageError(
                  f"Couldn't determine identity from value: {identity}"
              )
          actions = {"leave": [{"identity_id": identity_id}]}
      else:
          group = groups_client.get_group(group_id, include="my_memberships")
          memberships = [x for x in group["my_memberships"] if x["status"] == "active"]
          if not memberships:
              raise click.ClickException(f"You have no memberships in {group_id}")
          actions = {"leave": [{"identity_id": x["identity_id"]} for x in memberships]}
  
      response = groups_client.batch_membership_action(group_id, actions)
      # if this failed to return at least one 'leave', figure out an error to show
      if not response.get("leave", None):
          try:
              raise ValueError(response["errors"]["leave"][0]["detail"])
          except LookupError:
              raise ValueError("Could not leave group")
  
      formatted_print(response, text_format=group_leave_formatter)
code_tokens: def group_leave ( * , group_id : uuid . UUID , identity : Optional [ ParsedIdentity ] , login_manager : LoginManager , ) : auth_client = login_manager . get_auth_client ( ) groups_client = login_manager . get_groups_client ( ) if identity : identity_id = auth_client . maybe_lookup_identity_id ( identity . value ) if not identity_id : raise click . UsageError ( f"Couldn't determine identity from value: {identity}" ) actions = { "leave" : [ { "identity_id" : identity_id } ] } else : group = groups_client . get_group ( group_id , include = "my_memberships" ) memberships = [ x for x in group [ "my_memberships" ] if x [ "status" ] == "active" ] if not memberships : raise click . ClickException ( f"You have no memberships in {group_id}" ) actions = { "leave" : [ { "identity_id" : x [ "identity_id" ] } for x in memberships ] } response = groups_client . batch_membership_action ( group_id , actions ) if not response . get ( "leave" , None ) : try : raise ValueError ( response [ "errors" ] [ "leave" ] [ 0 ] [ "detail" ] ) except LookupError : raise ValueError ( "Could not leave group" ) formatted_print ( response , text_format = group_leave_formatter )
short_docstring: Leave a group in which you are a member.
short_docstring_tokens: Leave a group in which you are a member .
comment: """
      Leave a group in which you are a member.
  
      If multiple identities in your identity set are members, all memberships will be
      removed by default. If needed, use the `--identity` flag to control this behavior.
  
      You may not leave a group in which you are the last remaining `admin` user.
      """$SEP$# if this failed to return at least one 'leave', figure out an error to show