Implement communities, licenses, and access links CLI commands#37
Implement communities, licenses, and access links CLI commands#37
Conversation
Add user-facing CLI commands for the remaining read operations. - communities list [query]: search/list communities - licenses search [query]: search available licenses - access links list <id>: list share links for a record - All commands output via Format() respecting --output and --fields Closes #12 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR implements the final three read-only CLI commands for Phase 2: communities, licenses, and access links. These commands enable users to browse Zenodo communities, search for appropriate licenses, and view share links for records. All commands follow the established CLI patterns and support the standard --output and --fields flags for flexible output formatting.
Changes:
- Added
zenodo communities list [query]command to search/list Zenodo communities - Added
zenodo licenses search [query]command to search available licenses - Added
zenodo access links list <id>command to list share links for a record
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| internal/cli/communities.go | Implements communities list command with query parameter support |
| internal/cli/licenses.go | Implements licenses search command with query parameter support |
| internal/cli/access.go | Implements access links list command for viewing record share links |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| result, err := client.SearchCommunities(q, 0, 0) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| return output.Format(os.Stdout, result.Hits.Hits, appCtx.Output, appCtx.Fields) |
There was a problem hiding this comment.
Missing pagination feedback to user. Similar to the pattern in records.go (lines 55, 96), this command should print to stderr showing how many results are displayed versus the total available. Add "fmt" to imports and add fmt.Fprintf(os.Stderr, "Showing %d of %d communities\n", len(result.Hits.Hits), result.Hits.Total) before the return statement.
| result, err := client.SearchLicenses(q, 0, 0) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| return output.Format(os.Stdout, result.Hits.Hits, appCtx.Output, appCtx.Fields) |
There was a problem hiding this comment.
Missing pagination feedback to user. Similar to the pattern in records.go (lines 55, 96), this command should print to stderr showing how many results are displayed versus the total available. Add "fmt" to imports and add fmt.Fprintf(os.Stderr, "Showing %d of %d licenses\n", len(result.Hits.Hits), result.Hits.Total) before the return statement.
| var communitiesListCmd = &cobra.Command{ | ||
| Use: "list [query]", | ||
| Short: "List or search communities", | ||
| Long: `List or search Zenodo communities. | ||
|
|
||
| Examples: | ||
| zenodo communities list | ||
| zenodo communities list "open science" | ||
| zenodo communities list --output csv`, | ||
| Args: cobra.MaximumNArgs(1), | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| client := api.NewClient(appCtx.BaseURL, appCtx.Token) | ||
|
|
||
| q := "" | ||
| if len(args) > 0 { | ||
| q = args[0] | ||
| } | ||
|
|
||
| result, err := client.SearchCommunities(q, 0, 0) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| return output.Format(os.Stdout, result.Hits.Hits, appCtx.Output, appCtx.Fields) | ||
| }, | ||
| } |
There was a problem hiding this comment.
Consider adding an --all flag similar to the records commands (records.go lines 32, 74) to fetch all pages of results. The records commands use api.PaginateAll for this. While communities and licenses would need their own PaginateAll functions (since the current one is specific to RecordSearchResult), this would provide consistency with the records commands and handle cases where results exceed 100 items.
| var licensesSearchCmd = &cobra.Command{ | ||
| Use: "search [query]", | ||
| Short: "Search available licenses", | ||
| Long: `Search Zenodo's available licenses. | ||
|
|
||
| Examples: | ||
| zenodo licenses search | ||
| zenodo licenses search "creative commons" | ||
| zenodo licenses search "MIT" --output json`, | ||
| Args: cobra.MaximumNArgs(1), | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| client := api.NewClient(appCtx.BaseURL, appCtx.Token) | ||
|
|
||
| q := "" | ||
| if len(args) > 0 { | ||
| q = args[0] | ||
| } | ||
|
|
||
| result, err := client.SearchLicenses(q, 0, 0) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| return output.Format(os.Stdout, result.Hits.Hits, appCtx.Output, appCtx.Fields) | ||
| }, | ||
| } |
There was a problem hiding this comment.
Consider adding an --all flag similar to the records commands (records.go lines 32, 74) to fetch all pages of results. The records commands use api.PaginateAll for this. While communities and licenses would need their own PaginateAll functions (since the current one is specific to RecordSearchResult), this would provide consistency with the records commands and handle cases where results exceed 100 items.
ELI5
Now you can browse Zenodo communities ("what groups/organizations exist?"), search licenses ("what license should I pick for my dataset?"), and list share links for a record. These are the last three read-only commands, completing Phase 2's user-facing CLI.
Summary
zenodo communities list [query]— search/list Zenodo communitieszenodo licenses search [query]— search available licenseszenodo access links list <id>— list share links for a record--outputand--fieldsflagsCode changes
internal/cli/communities.gocommunities listcommandinternal/cli/licenses.golicenses searchcommandinternal/cli/access.goaccess links listcommandTest plan
go build ./...compilesgo test ./...— all 54 tests passCloses #12
🤖 Generated with Claude Code