-
Notifications
You must be signed in to change notification settings - Fork 37
feat: Add --category flag to docs search command #603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,8 +30,23 @@ var docsBaseURL = "https://docs.slack.dev" | |
|
|
||
| const docsSearchMethod = "api/v1/search" | ||
|
|
||
| // DocsSearchCategories lists the categories the docs search endpoint accepts, | ||
| // mirroring the filters offered by the docs site search modal. An empty | ||
| // category searches across all content. | ||
| var DocsSearchCategories = []string{ | ||
| "guides", | ||
| "reference", | ||
| "changelog", | ||
| "python", | ||
| "javascript", | ||
| "java", | ||
| "slack_cli", | ||
| "slack_github_action", | ||
| "deno_slack_sdk", | ||
| } | ||
|
Comment on lines
+33
to
+46
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🪓 thought: I'd favor removing checks for categories from the CLI to leave as API validation instead. Either zero results returned or an error of some kind? 🌲 ramble: I'm suggesting this to avoid incompatible CLI versions with iterations of search - adding a new category to docs would require releasing and updating to unlock that which is somewhat inconvenient... |
||
|
|
||
| type DocsClient interface { | ||
| DocsSearch(ctx context.Context, query string, limit int) (*DocsSearchResponse, error) | ||
| DocsSearch(ctx context.Context, query string, limit int, category string) (*DocsSearchResponse, error) | ||
| } | ||
|
|
||
| type DocsSearchResponse struct { | ||
|
|
@@ -45,8 +60,11 @@ type DocsSearchItem struct { | |
| Title string `json:"title"` | ||
| } | ||
|
|
||
| func buildDocsSearchURL(baseURL, query string, limit int) (string, error) { | ||
| func buildDocsSearchURL(baseURL, query string, limit int, category string) (string, error) { | ||
| endpoint := fmt.Sprintf("%s?query=%s&limit=%d", docsSearchMethod, url.QueryEscape(query), limit) | ||
| if category != "" { | ||
| endpoint += fmt.Sprintf("&category=%s", url.QueryEscape(category)) | ||
| } | ||
| sURL, err := url.Parse(baseURL + "/" + endpoint) | ||
| if err != nil { | ||
| return "", err | ||
|
|
@@ -64,12 +82,12 @@ func buildDocsSearchRequest(ctx context.Context, urlStr, cliVersion string) (*ht | |
| } | ||
|
|
||
| // DocsSearch searches the Slack developer docs API | ||
| func (c *Client) DocsSearch(ctx context.Context, query string, limit int) (*DocsSearchResponse, error) { | ||
| func (c *Client) DocsSearch(ctx context.Context, query string, limit int, category string) (*DocsSearchResponse, error) { | ||
| var span opentracing.Span | ||
| span, _ = opentracing.StartSpanFromContext(ctx, "apiclient.DocsSearch") | ||
| defer span.Finish() | ||
|
|
||
| urlStr, err := buildDocsSearchURL(docsBaseURL, query, limit) | ||
| urlStr, err := buildDocsSearchURL(docsBaseURL, query, limit, category) | ||
| if err != nil { | ||
| return nil, errHTTPRequestFailed.WithRootCause(err) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗣️ note: Related to less validation within the CLI - if checking categories remains meaningful I'd favor either a warning output for unexpected values or an option to use
--forceas a workaround.