Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 0.48.1 - Unreleased

- Contacts: default `contacts search` and `contacts other search` to `--max 30`, the most results Google returns for these searches, and say so on stderr when a larger `--max` is given. Both previously asked for 50 and showed at most 30 with no sign the list was cut short. (#1323) — thanks @saariuslystoned.

## 0.48.0 - 2026-11-05

**Highlights:** New backups stay local until you configure a remote; existing configurations keep working. Store service-account keys in the keyring, search Gmail IDs efficiently, and use environment-backed watch tokens, with Calendar fixes and security dependency updates.
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/gog-contacts-other-search.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ gog contacts (contact) other search <query> ... [flags]
| `-h`<br>`--help` | `kong.helpFlag` | | Show context-sensitive help. |
| `--home` | `string` | | Override gogcli config/data/state/cache root (equivalent to GOG_HOME) |
| `-j`<br>`--json`<br>`--machine` | `bool` | false | Output JSON to stdout (best for scripting) |
| `--max`<br>`--limit` | `int64` | 50 | Max results |
| `--max`<br>`--limit` | `int64` | 30 | Max results (Google returns at most 30) |
| `--no-input`<br>`--non-interactive`<br>`--noninteractive` | `bool` | | Never prompt; fail instead (useful for CI) |
| `-p`<br>`--plain`<br>`--tsv` | `bool` | false | Output stable, parseable text to stdout (TSV; no colors) |
| `--quota-project` | `string` | | Google Cloud project to bill for API usage (sent as X-Goog-User-Project; some APIs require it with --access-token or ADC) |
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/gog-contacts-search.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ gog contacts (contact) search <query> ... [flags]
| `-h`<br>`--help` | `kong.helpFlag` | | Show context-sensitive help. |
| `--home` | `string` | | Override gogcli config/data/state/cache root (equivalent to GOG_HOME) |
| `-j`<br>`--json`<br>`--machine` | `bool` | false | Output JSON to stdout (best for scripting) |
| `--max`<br>`--limit` | `int64` | 50 | Max results |
| `--max`<br>`--limit` | `int64` | 30 | Max results (Google returns at most 30) |
| `--no-input`<br>`--non-interactive`<br>`--noninteractive` | `bool` | | Never prompt; fail instead (useful for CI) |
| `-p`<br>`--plain`<br>`--tsv` | `bool` | false | Output stable, parseable text to stdout (TSV; no colors) |
| `--quota-project` | `string` | | Google Cloud project to bill for API usage (sent as X-Goog-User-Project; some APIs require it with --access-token or ADC) |
Expand Down
19 changes: 17 additions & 2 deletions internal/cmd/contacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type ContactsCmd struct {

type ContactsSearchCmd struct {
Query []string `arg:"" name:"query" help:"Search query"`
Max int64 `name:"max" aliases:"limit" help:"Max results" default:"50"`
Max int64 `name:"max" aliases:"limit" help:"Max results (Google returns at most 30)" default:"30"`
}

func (c *ContactsSearchCmd) Run(ctx context.Context, flags *RootFlags) error {
Expand All @@ -50,7 +50,7 @@ func (c *ContactsSearchCmd) Run(ctx context.Context, flags *RootFlags) error {
warmSearchContactsCache(ctx, svc)
resp, err := svc.People.SearchContacts().
Query(query).
PageSize(c.Max).
PageSize(peopleSearchPageSize(u, c.Max)).
ReadMask(contactsReadMask).
Do()
if err != nil {
Expand Down Expand Up @@ -267,3 +267,18 @@ func userDefinedFields(p *people.Person) map[string]string {
}
return fields
}

// peopleSearchMaxPageSize is the most results people.searchContacts and
// otherContacts.search return: larger pageSize values are capped to 30 and
// neither method returns a page token.
const peopleSearchMaxPageSize = 30

func peopleSearchPageSize(u *ui.UI, requested int64) int64 {
if requested <= peopleSearchMaxPageSize {
return requested
}
if u != nil {
u.Err().Linef("# Google returns at most %d contact search results; showing up to %d of the requested %d", peopleSearchMaxPageSize, peopleSearchMaxPageSize, requested)
}
return peopleSearchMaxPageSize
}
4 changes: 2 additions & 2 deletions internal/cmd/contacts_directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func (c *ContactsOtherListCmd) Run(ctx context.Context, flags *RootFlags) error

type ContactsOtherSearchCmd struct {
Query []string `arg:"" name:"query" help:"Search query"`
Max int64 `name:"max" aliases:"limit" help:"Max results" default:"50"`
Max int64 `name:"max" aliases:"limit" help:"Max results (Google returns at most 30)" default:"30"`
}

func (c *ContactsOtherSearchCmd) Run(ctx context.Context, flags *RootFlags) error {
Expand All @@ -328,7 +328,7 @@ func (c *ContactsOtherSearchCmd) Run(ctx context.Context, flags *RootFlags) erro
resp, err := svc.OtherContacts.Search().
Query(query).
ReadMask(contactsOtherReadMask).
PageSize(c.Max).
PageSize(peopleSearchPageSize(u, c.Max)).
Do()
if err != nil {
return err
Expand Down
77 changes: 77 additions & 0 deletions internal/cmd/contacts_search_page_cap_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package cmd

import (
"encoding/json"
"fmt"
"net/http"
"strconv"
"strings"
"sync/atomic"
"testing"
)

// Both people.searchContacts and otherContacts.search cap pageSize at 30 and
// return no page token, so a larger --max can never be met.
func capped30SearchHandler(endpoint string, sent *atomic.Value) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if !strings.Contains(r.URL.Path, endpoint) || r.URL.Query().Get("query") == "" {
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(map[string]any{"results": []any{}})
return
}
sent.Store(r.URL.Query().Get("pageSize"))
n, _ := strconv.Atoi(r.URL.Query().Get("pageSize"))
if n > 30 {
n = 30
}
results := make([]map[string]any, 0, n)
for i := range n {
results = append(results, map[string]any{"person": map[string]any{
"resourceName": fmt.Sprintf("people/c%d", i),
"names": []map[string]any{{"displayName": fmt.Sprintf("Ada %d", i)}},
}})
}
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(map[string]any{"results": results})
}
}

func TestContactsSearch_RespectsThe30ResultCap(t *testing.T) {
for _, tc := range []struct {
name string
verb []string
endpoint string
}{
{name: "contacts search", verb: []string{"contacts", "search", "ada"}, endpoint: "people:searchContacts"},
{name: "contacts other search", verb: []string{"contacts", "other", "search", "ada"}, endpoint: "otherContacts:search"},
} {
for _, flags := range []struct {
args []string
wantWarn bool
}{
{args: nil, wantWarn: false},
{args: []string{"--max", "50"}, wantWarn: true},
} {
t.Run(fmt.Sprintf("%s %v", tc.name, flags.args), func(t *testing.T) {
var sent atomic.Value
svc, closeSrv := newPeopleService(t, capped30SearchHandler(tc.endpoint, &sent))
t.Cleanup(closeSrv)
args := append(append([]string{"--json", "--account", "a@b.com"}, tc.verb...), flags.args...)
res := executeWithPeopleTestServices(t, args, peopleTestServices{
Contacts: fixedPeopleTestService(svc),
Other: fixedPeopleTestService(svc),
})
if res.err != nil {
t.Fatalf("Execute: %v", res.err)
}
if got := sent.Load(); got != "30" {
t.Fatalf("pageSize sent = %v, want 30", got)
}
warned := strings.Contains(res.stderr, "30")
if warned != flags.wantWarn {
t.Fatalf("stderr = %q, want warning about the 30-result cap: %v", res.stderr, flags.wantWarn)
}
})
}
}
}
Loading