feat: add slack docs search subcommand #433
feat: add slack docs search subcommand #433lukegalbraithrussell wants to merge 10 commits intomainfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #433 +/- ##
==========================================
+ Coverage 70.32% 70.47% +0.14%
==========================================
Files 220 222 +2
Lines 18506 18605 +99
==========================================
+ Hits 13015 13111 +96
- Misses 4313 4314 +1
- Partials 1178 1180 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
cmd/docs/search.go
Outdated
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| const docsSearchAPIURL = "https://docs-slack-d-search-api-duu9zr.herokuapp.com/api/search" |
There was a problem hiding this comment.
This will be updated to docs.slack.dev once api endpoint PR is merged in private docs repo
There was a problem hiding this comment.
| const docsSearchAPIURL = "https://docs-slack-d-search-api-duu9zr.herokuapp.com/api/search" | |
| const docsURL = "https://docs-slack-d-search-api-duu9zr.herokuapp.com/" |
🪬 suggestion: We might want to abstract this to the docs/docs.go file since we target it in multiple places? It might be useful for testing changes too?
srtaalej
left a comment
There was a problem hiding this comment.
left some comments about terminal ouput and tests but these changes are looking really good ⭐ ! lets get those addressed so we can merge 😝
cmd/docs/search.go
Outdated
| return nil | ||
| } | ||
|
|
||
| func fetchAndOutputSearchResults(ctx context.Context, clients *shared.ClientFactory, query string, limit int, httpClient *http.Client) error { |
There was a problem hiding this comment.
it'd be nice if URLs were full https://docs.slack.dev URLs so they're cmd+clickable in the terminal
{
"url": "https://docs.slack.dev/block-kit/",
"title": "Block Kit"
},right now the json outputs as
{
"url": "/block-kit/",
"title": "Block Kit"
},There was a problem hiding this comment.
📚 thought: I agree listing entire links is ideal and might suggest we add a text format with this?
$ slack docs search "Block Kit" --output=text👾 ramble: If this format is supported it seems awkward to write that flag instead of defaulting to it but this is personal preference I think!
There was a problem hiding this comment.
@lukegalbraithrussell This is an awesome feature to be bringing 📚 ✨
I'm leaving a handful of comments that do request changes, but I'm hoping we can work through these:
- The API method logic is included with command: I understand we reach a different host but we might still find
apipackage useful. - Defaulting outputs for the person reading: I'm a fan of JSON but find this jarring when hoping for a quick search in terminal. I instead suggest a default
textoutput to use section formatting:
$ slack docs search "Block Kit"- Deprecating the "--search" flag: Can we make this a separate PR? Adding JSON outputs might be blocking this PR from merging now, but I think those changes have a faster review 🏁
- Standardizing the
docs.slack.devAPI client: We're starting to find the same URL in multiple places and I'm hoping changes toward a standard place for this has good pattern? - Erroring for unexpected inputs: One comment also notes that we should error instead of opening browsers for unexpected output types 👻
Please do let me know if I can share more toward these changes. I'd love to see this land 💌
cmd/docs/docs.go
Outdated
| } | ||
|
|
||
| cmd.Flags().BoolVar(&searchMode, "search", false, "open Slack docs search page or search with query") | ||
| cmd.Flags().BoolVar(&searchMode, "search", false, "[DEPRECATED] open Slack docs search page or search with query (use 'docs search' subcommand instead)") |
There was a problem hiding this comment.
| cmd.Flags().BoolVar(&searchMode, "search", false, "[DEPRECATED] open Slack docs search page or search with query (use 'docs search' subcommand instead)") | |
| // DEPRECATED(semver:major): Remove in favor of "search" command | |
| cmd.Flags().BoolVar(&searchMode, "search", false, "open Slack docs search page or search with query") | |
| cmd.Flag("search").Hidden = true |
🔭 suggestion: Let's prefer to hide deprecated features!
cmd/docs/search.go
Outdated
| return nil | ||
| } | ||
|
|
||
| func fetchAndOutputSearchResults(ctx context.Context, clients *shared.ClientFactory, query string, limit int, httpClient *http.Client) error { |
There was a problem hiding this comment.
📚 thought: I agree listing entire links is ideal and might suggest we add a text format with this?
$ slack docs search "Block Kit" --output=text👾 ramble: If this format is supported it seems awkward to write that flag instead of defaulting to it but this is personal preference I think!
cmd/docs/search.go
Outdated
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| const docsSearchAPIURL = "https://docs-slack-d-search-api-duu9zr.herokuapp.com/api/search" |
There was a problem hiding this comment.
| const docsSearchAPIURL = "https://docs-slack-d-search-api-duu9zr.herokuapp.com/api/search" | |
| const docsURL = "https://docs-slack-d-search-api-duu9zr.herokuapp.com/" |
🪬 suggestion: We might want to abstract this to the docs/docs.go file since we target it in multiple places? It might be useful for testing changes too?
Changelog
Adds
slack docs searchsubcommand. It can output search results as JSONSummary
slack docs search<query>--outputtexttext' , 'browserorjson--limit20Examples
Code coverage notes
The following lines in
search.gohave incomplete test coverage. They seemed cumbersome to cover.(Summarized by Claude)
Lines 88-89 (
if cfg.output == "json"branch): Conditional routing logic that's difficult to test through the command framework. The actual JSON output logic is thoroughly tested via direct function calls.Lines 129-130 (JSON encoding error handling): Defensive error handling for an unrealistic scenario (broken pipe when piping output). Most CLI tools don't explicitly handle this edge case.
Requirements