Skip to content

Commit 0a31daa

Browse files
feat(api): manual updates
1 parent fa3ce88 commit 0a31daa

4 files changed

Lines changed: 80 additions & 3 deletions

File tree

‎.stats.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 37
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-eac90d0a78d6166dc64c49ad4cd44883ab0bd357063ff09e60ed78085e2bde3c.yml
1+
configured_endpoints: 38
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-155e4761d62255841349c0f8a01b0a9c463ea1d1f2d6c4fd8d1a75c8bef6f226.yml
33
openapi_spec_hash: ab91f77e7c9d992400cbc7fc8a9e76c1
4-
config_hash: 2bea1743c84d63bd61f8501a6ea63065
4+
config_hash: bff282047fafdad771fb7ec685f56944

‎pkg/cmd/brand.go‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,27 @@ var brandRetrieveSimplified = cli.Command{
152152
HideHelpCommand: true,
153153
}
154154

155+
var brandSearch = cli.Command{
156+
Name: "search",
157+
Usage: "Search brands by name or domain and get back up to 10 lightweight matches\n(domain, name, logo), most popular first: by Tranco rank, then market cap for\nbrands outside the Tranco list, with text relevance breaking ties. Matching is\nprefix-based with no typo tolerance, so it is suited to autocomplete. Only\nbrands already in the Context.dev index are returned — use /brand/retrieve to\nfetch (and index) a specific domain. Free on Pro and Scale plans; costs 1 credit\nper request on the Free and Starter plans.",
158+
Suggest: true,
159+
Flags: []cli.Flag{
160+
&requestflag.Flag[string]{
161+
Name: "query",
162+
Usage: "Search term, matched against brand names and domains by prefix (e.g. 'nike', 'nike.com', 'nik').",
163+
Required: true,
164+
QueryPath: "query",
165+
},
166+
&requestflag.Flag[[]string]{
167+
Name: "tag",
168+
Usage: "Optional comma-separated caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.",
169+
QueryPath: "tags",
170+
},
171+
},
172+
Action: handleBrandSearch,
173+
HideHelpCommand: true,
174+
}
175+
155176
func handleBrandRetrieve(ctx context.Context, cmd *cli.Command) error {
156177
client := contextdev.NewClient(getDefaultRequestOptions(cmd)...)
157178
unusedArgs := cmd.Args().Slice()
@@ -233,3 +254,44 @@ func handleBrandRetrieveSimplified(ctx context.Context, cmd *cli.Command) error
233254
Transform: transform,
234255
})
235256
}
257+
258+
func handleBrandSearch(ctx context.Context, cmd *cli.Command) error {
259+
client := contextdev.NewClient(getDefaultRequestOptions(cmd)...)
260+
unusedArgs := cmd.Args().Slice()
261+
262+
if len(unusedArgs) > 0 {
263+
return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs)
264+
}
265+
266+
options, err := flagOptions(
267+
cmd,
268+
apiquery.NestedQueryFormatBrackets,
269+
apiquery.ArrayQueryFormatComma,
270+
EmptyBody,
271+
false,
272+
)
273+
if err != nil {
274+
return err
275+
}
276+
277+
params := contextdev.BrandSearchParams{}
278+
279+
var res []byte
280+
options = append(options, option.WithResponseBodyInto(&res))
281+
_, err = client.Brand.Search(ctx, params, options...)
282+
if err != nil {
283+
return err
284+
}
285+
286+
obj := gjson.ParseBytes(res)
287+
format := cmd.Root().String("format")
288+
explicitFormat := cmd.Root().IsSet("format")
289+
transform := cmd.Root().String("transform")
290+
return ShowJSON(obj, ShowJSONOpts{
291+
ExplicitFormat: explicitFormat,
292+
Format: format,
293+
RawOutput: cmd.Root().Bool("raw-output"),
294+
Title: "brand search",
295+
Transform: transform,
296+
})
297+
}

‎pkg/cmd/brand_test.go‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,17 @@ func TestBrandRetrieveSimplified(t *testing.T) {
6262
)
6363
})
6464
}
65+
66+
func TestBrandSearch(t *testing.T) {
67+
t.Skip("Mock server tests are disabled")
68+
t.Run("regular flags", func(t *testing.T) {
69+
mocktest.TestRunMockTestWithFlags(
70+
t,
71+
"--api-key", "string",
72+
"brand", "search",
73+
"--query", "x",
74+
"--tag", "production",
75+
"--tag", "team-alpha",
76+
)
77+
})
78+
}

‎pkg/cmd/cmd.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ func init() {
126126
Commands: []*cli.Command{
127127
&brandRetrieve,
128128
&brandRetrieveSimplified,
129+
&brandSearch,
129130
},
130131
},
131132
{

0 commit comments

Comments
 (0)