Skip to content

Add shell completions and version flag with build info#42

Merged
ran-codes merged 1 commit intomainfrom
issue-17/completions-version
Feb 17, 2026
Merged

Add shell completions and version flag with build info#42
ran-codes merged 1 commit intomainfrom
issue-17/completions-version

Conversation

@ran-codes
Copy link
Copy Markdown
Owner

ELI5

Two quality-of-life features: (1) tab completion — type zenodo rec<TAB> and it fills in records for bash/zsh/fish/powershell, and (2) zenodo version shows the version number, git commit, and build date. The version info gets baked in at build time via Go's -ldflags, so goreleaser (#18) will inject the real values automatically.

Summary

  • zenodo completion [bash|zsh|fish|powershell] generates shell completion scripts
  • zenodo version prints version, commit hash, build date
  • Version/commit/date set via -ldflags at build time (defaults to "dev"/"unknown")

Code changes

File What
internal/cli/completion.go Completion command for 4 shells
internal/cli/version.go Version command with ldflags vars

Test plan

  • go test ./... — all 75 tests pass
  • zenodo version prints "dev" (default)
  • go build -ldflags "-X ...version=0.1.0" then zenodo version prints "0.1.0"
  • zenodo completion bash generates valid completion script

Closes #17

🤖 Generated with Claude Code

- completion command: generates bash, zsh, fish, powershell scripts
- version command: prints version, git commit, build date
- Build info injected via -ldflags at build time

Closes #17

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 17, 2026 20:00
@ran-codes ran-codes merged commit 7ea016f into main Feb 17, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds two quality-of-life features to the Zenodo CLI: shell completion generation for bash/zsh/fish/powershell and a version command that displays build information (version, commit hash, and build date). The version information is designed to be injected at build time via Go's -ldflags mechanism, which will work seamlessly with goreleaser when it's configured in issue #18.

Changes:

  • Added zenodo completion [bash|zsh|fish|powershell] command to generate shell-specific completion scripts
  • Added zenodo version subcommand to display version, commit hash, and build date
  • Version variables default to "dev"/"unknown" and can be overridden via ldflags at build time

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
internal/cli/completion.go Implements completion command with support for 4 shells (bash, zsh, fish, powershell) using cobra's built-in completion generators
internal/cli/version.go Implements version command with ldflags-injectable build variables for version, commit, and date

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +16 to +28
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print version and build information",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("zenodo %s\n", version)
fmt.Printf(" commit: %s\n", commit)
fmt.Printf(" built: %s\n", date)
},
}

func init() {
rootCmd.AddCommand(versionCmd)
}
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue #17 specifies a --version flag on the root command, but the implementation provides a version subcommand instead. While both patterns are acceptable in CLI design, this doesn't match the original requirement. Consider either: (1) adding a --version flag to the root command by setting the Version field on rootCmd and using cobra's built-in version flag support, or (2) updating issue #17 to reflect that a subcommand approach is being used. Many modern CLIs support both patterns (e.g., kubectl version and kubectl --version both work).

Copilot uses AI. Check for mistakes.
Comment on lines +19 to +22
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("zenodo %s\n", version)
fmt.Printf(" commit: %s\n", commit)
fmt.Printf(" built: %s\n", date)
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with all other commands in the codebase (records.go, communities.go, config.go, etc.), consider using RunE instead of Run. While fmt.Printf errors are rare, using RunE provides consistent error handling patterns and allows for proper error propagation if needed. All other cobra.Command definitions in internal/cli/ use RunE.

Suggested change
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("zenodo %s\n", version)
fmt.Printf(" commit: %s\n", commit)
fmt.Printf(" built: %s\n", date)
RunE: func(cmd *cobra.Command, args []string) error {
if _, err := fmt.Printf("zenodo %s\n", version); err != nil {
return err
}
if _, err := fmt.Printf(" commit: %s\n", commit); err != nil {
return err
}
if _, err := fmt.Printf(" built: %s\n", date); err != nil {
return err
}
return nil

Copilot uses AI. Check for mistakes.
Comment on lines +50 to +51
}
return nil
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This return statement is unreachable because the switch statement above handles all possible values validated by cobra.OnlyValidArgs. Since all four valid args (bash, zsh, fish, powershell) are explicitly handled in the switch cases and each returns, execution will never reach this line. Consider removing this unreachable return statement.

Suggested change
}
return nil
default:
return nil
}

Copilot uses AI. Check for mistakes.
@ran-codes ran-codes deleted the issue-17/completions-version branch February 18, 2026 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add shell completions and version flag with build info

2 participants