<commit_before>package shield

import (
	"fmt"
	"strings"

	qs "github.com/jhunt/go-querytron"
	"github.com/pborman/uuid"
)

type Tenant struct {
	UUID string `json:"uuid,omitempty"`
	Name string `json:"name"`

	Members []struct {
		UUID    string `json:"uuid,omitempty"`
		Name    string `json:"name"`
		Account string `json:"account"`
		Backend string `json:"backend"`
		Role    string `json:"role"`
	} `json:"members"`
}

type TenantFilter struct {
	Fuzzy bool   `qs:"exact:f:t"`
	Name  string `qs:"name"`
}

func (c *Client) ListTenants(filter *TenantFilter) ([]*Tenant, error) {
	u := qs.Generate(filter).Encode()
	var out []*Tenant
	return out, c.get(fmt.Sprintf("/v2/tenants?%s", u), &out)
}

func (c *Client) GetMyTenants() ([]*Tenant, error) {
	id, err := c.AuthID()
	if err != nil {
		return nil, err
	}

	l := make([]*Tenant, len(id.Tenants))
	for i := range id.Tenants {
		l[i] = &Tenant{
			UUID: id.Tenants[i].UUID,
			Name: id.Tenants[i].Name,
		}
	}

	return l, nil
}

func (c *Client) FindMyTenant(q string, fuzzy bool) (*Tenant, error) {
	tenants, err := c.GetMyTenants()
	if err != nil {
		return nil, err
	}

	q = strings.ToLower(q)
	l := make([]*Tenant, 0)
	for _, tenant := range tenants {
		if !fuzzy && (tenant.UUID == q || strings.ToLower(tenant.Name) == q) {
			l = append(l, tenant)
		} else if fuzzy && strings.Contains(strings.ToLower(tenant.Name), q) {
			l = append(l, tenant)
		}
	}

	if len(l) == 0 {
		if fuzzy {
			return nil, fmt.Errorf("no tenants matching '*%s*'", q)
		}
		return nil, fmt.Errorf("no tenant named '%s'", q)
	}
<commit_msg>Allow UUID fuzzy search for `--tenant`<commit_after>package shield

import (
	"fmt"
	"strings"

	qs "github.com/jhunt/go-querytron"
	"github.com/pborman/uuid"
)

type Tenant struct {
	UUID string `json:"uuid,omitempty"`
	Name string `json:"name"`

	Members []struct {
		UUID    string `json:"uuid,omitempty"`
		Name    string `json:"name"`
		Account string `json:"account"`
		Backend string `json:"backend"`
		Role    string `json:"role"`
	} `json:"members"`
}

type TenantFilter struct {
	Fuzzy bool   `qs:"exact:f:t"`
	Name  string `qs:"name"`
}

func (c *Client) ListTenants(filter *TenantFilter) ([]*Tenant, error) {
	u := qs.Generate(filter).Encode()
	var out []*Tenant
	return out, c.get(fmt.Sprintf("/v2/tenants?%s", u), &out)
}

func (c *Client) GetMyTenants() ([]*Tenant, error) {
	id, err := c.AuthID()
	if err != nil {
		return nil, err
	}

	l := make([]*Tenant, len(id.Tenants))
	for i := range id.Tenants {
		l[i] = &Tenant{
			UUID: id.Tenants[i].UUID,
			Name: id.Tenants[i].Name,
		}
	}

	return l, nil
}

func (c *Client) FindMyTenant(q string, fuzzy bool) (*Tenant, error) {
	tenants, err := c.GetMyTenants()
	if err != nil {
		return nil, err
	}

	q = strings.ToLower(q)
	l := make([]*Tenant, 0)
	for _, tenant := range tenants {
		if !fuzzy && (tenant.UUID == q || strings.ToLower(tenant.Name) == q) {
			l = append(l, tenant)
		} else if fuzzy && strings.Contains(strings.ToLower(tenant.Name), q) {
			l = append(l, tenant)
		} else if fuzzy && strings.HasPrefix(strings.ToLower(tenant.UUID), q) {
			l = append(l, tenant)
		}
	}

	if len(l) == 0 {
		if fuzzy {
			return nil, fmt.Errorf("no tenants matching '*%s*'", q)
		}
		return nil, fmt.Errorf("no tenant named '%s'", q)
	}

{'fraction_non_alphanumeric': 0.18242830994508846, 'fraction_numerical': 0.0018303843807199512, 'mean_word_length': 3.7247838616714697, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '892732', 'n_tokens_mistral': 1365, 'n_tokens_neox': 1282, 'n_words': 323}