Skip to content

Conversation

@ourines
Copy link
Owner

@ourines ourines commented Feb 10, 2026

Summary

Closes #12

  • Shell completion: Add codes completion [bash|zsh|fish|powershell] command with Cobra's built-in generators. Dynamic completion for config names (test), project names (start, project remove), and static values (defaultbehavior set, skippermissions set, config set/get).
  • Merge installinit: codes init now handles binary self-install to PATH + automatic shell completion setup + environment health checks. The standalone install command is removed.
  • Quick install script: curl -fsSL .../install.sh | sh for one-liner setup.
  • README & Makefile updates: Reflect all changes above.

Changes

File What changed
internal/commands/cobra.go CompletionCmd + completeConfigNames / completeProjectNames + ValidArgsFunction on 6 commands, removed InstallCmd
internal/commands/commands.go installBinary() + installShellCompletion() + appendCompletionLine() helpers, merged into RunInit(), removed RunInstall()
cmd/codes/main.go Register CompletionCmd, remove InstallCmd
Makefile Update test and install targets
install.sh New POSIX-compatible quick install script
README.md Add Quick Install, completion docs, update init description, remove install section

Test plan

  • go build ./... passes
  • codes completion bash/zsh/fish/powershell all generate scripts successfully
  • codes __complete completion "" returns bash zsh fish powershell
  • codes __complete defaultbehavior set "" returns current last home
  • codes __complete skippermissions set "" returns true false
  • codes install returns "unknown command" (removed)
  • Manual: source <(codes completion zsh) then TAB completion works
  • Manual: codes init installs binary + sets up completion + runs health check

Summary by CodeRabbit

  • New Features

    • One-line installation script for quick setup via curl
    • Shell completion support for bash, zsh, fish, and PowerShell
    • Enhanced codes init command that automatically configures shell completion and performs environment checks
  • Documentation

    • Updated installation and setup guides to reflect the new init-based workflow

- Add `codes completion [bash|zsh|fish|powershell]` command using Cobra's
  built-in completion generators
- Add dynamic completion for config names, project names, and static
  values on relevant subcommands
- Merge `install` command into `init`: now `codes init` handles binary
  self-install, shell completion setup, and environment health checks
- Add install.sh for quick curl-pipe installation
- Update README and Makefile to reflect the changes
@coderabbitai
Copy link

coderabbitai bot commented Feb 10, 2026

Warning

Rate limit exceeded

@ourines has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 4 minutes and 7 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📝 Walkthrough

Walkthrough

The changes refactor the CLI installation flow from an "install" command to a unified "init" command that handles binary installation, shell completion setup, and environment verification. Shell completion support for bash, zsh, fish, and PowerShell is introduced with dynamic completions for config and project names across various commands. Documentation, build configuration, and command registration are updated accordingly.

Changes

Cohort / File(s) Summary
Command Structure
cmd/codes/main.go, internal/commands/cobra.go
CompletionCmd added with support for bash, zsh, fish, and PowerShell; InstallCmd removed from root registration; dynamic completion functions added (completeConfigNames, completeProjectNames); existing commands augmented with ValidArgsFunction and ValidArgs for completion.
Installation Flow Refactoring
internal/commands/commands.go, Makefile
RunInstall replaced with modular installBinary and installShellCompletion functions; RunInit expanded to handle binary installation, shell completion setup, and environment checks; install target now depends on build and invokes init instead of install.
Automated Install Script
install.sh
New shell script for automated downloading and installing the codes binary; detects OS and architecture; handles fallback installation paths (/usr/local/bin, ~/bin); executes init command post-installation.
Documentation
README.md
Quick Install section added with curl-based install snippet; installation instructions updated from install to init command; codes completion command documented with manual setup examples; troubleshooting section updated to reflect init-based flow.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Hop, hop, the init's here!
Shell completion, crystal clear!
Bash and zsh and fish galore,
Setup simpler than before!
No more fuss with paths and bins,
Let the coding journey begin!

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the two main changes: adding shell completion support and merging the install command into init, making it clear and specific.
Linked Issues check ✅ Passed The PR fully implements all requirements from issue #12: completion command for bash/zsh/fish/powershell and dynamic completions for config/project names.
Out of Scope Changes check ✅ Passed The PR includes additional changes beyond issue #12 scope: merging install into init, adding install.sh script, and updating documentation. While not explicitly mentioned in the issue, these are related infrastructure improvements supporting the completion feature.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/shell-completion

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 Fix all issues with AI agents
In `@internal/commands/commands.go`:
- Around line 601-615: RunInit doesn't check the success of installBinary() and
installShellCompletion(), so failures aren't reflected in the allGood flag;
update RunInit to capture the return values from installBinary and
installShellCompletion (the functions that currently return ("", bool)) and set
allGood = allGood && ok (or set to false on failure) and surface any error
output as needed so the final "All checks passed!" reflects actual install
success. Reference: RunInit, installBinary, installShellCompletion, and the
allGood variable.
- Around line 532-575: The installShellCompletion function currently ignores the
error from os.UserHomeDir(), which can leave homeDir empty and cause writes to
root; change the call to capture the error (homeDir, err := os.UserHomeDir()),
check err and bail out with a ui.ShowWarning or ui.ShowError before proceeding,
returning early to avoid constructing paths with an empty homeDir; update uses
in branches (zsh/bash/fish) to rely on the validated homeDir and keep existing
calls like appendCompletionLine, os.MkdirAll, os.WriteFile unchanged.
- Around line 469-530: The installBinary function currently ignores errors from
os.UserHomeDir() (calls near UserHomeDir usage for "windows" and default
fallback) which can produce invalid target paths; update both os.UserHomeDir()
calls to check the returned error and handle it by calling ui.ShowError with a
clear message and returning "", false (or otherwise aborting installation)
instead of proceeding with an empty homeDir; ensure you reference the same
symbols (installBinary, targetDir, installPath) and place the error checks
immediately after each os.UserHomeDir() call so the function never constructs or
writes to paths derived from an empty home directory.

In `@README.md`:
- Around line 127-135: The fenced code block containing the
installation/checklist output (the block that begins with triple backticks and
lines like "✓ Binary installed to /usr/local/bin/codes" and "✓ Default
configuration is working") is missing a language specifier; update that block to
use a language identifier such as text (e.g., change the opening backticks to
```text) so markdownlint MD040 is satisfied and the snippet is explicitly marked
as plain text.
🧹 Nitpick comments (2)
internal/commands/commands.go (1)

512-516: Consider streaming the binary copy instead of ReadFile.

os.ReadFile loads the entire binary into memory. Go binaries can be 20–50+ MB. Using io.Copy between file handles would be more memory-efficient.

♻️ Suggested refactor
-	sourceData, err := os.ReadFile(executablePath)
-	if err != nil {
-		ui.ShowError("Failed to read executable", err)
-		return "", false
-	}
-
-	if err := os.WriteFile(installPath, sourceData, 0755); err != nil {
-		ui.ShowError("Failed to write to target location", err)
-		return "", false
-	}
+	src, err := os.Open(executablePath)
+	if err != nil {
+		ui.ShowError("Failed to read executable", err)
+		return "", false
+	}
+	defer src.Close()
+
+	dst, err := os.OpenFile(installPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0755)
+	if err != nil {
+		ui.ShowError("Failed to write to target location", err)
+		return "", false
+	}
+	defer dst.Close()
+
+	if _, err := io.Copy(dst, src); err != nil {
+		ui.ShowError("Failed to copy executable", err)
+		return "", false
+	}
internal/commands/cobra.go (1)

336-347: completeProjectNames returns ShellCompDirectiveDefault, which enables file completion alongside project names.

This is appropriate for StartCmd (which accepts both project names and file paths), but for ProjectRemoveCmd (Line 255), file path suggestions are misleading since it only accepts project names.

Consider either splitting into two functions or having ProjectRemoveCmd use its own completion that returns ShellCompDirectiveNoFileComp.

♻️ Suggested approach
 // completeProjectNames provides dynamic completion for project names
-func completeProjectNames(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
+func completeProjectNames(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
+	projects, err := config.ListProjects()
+	if err != nil {
+		return nil, cobra.ShellCompDirectiveNoFileComp
+	}
+	var names []string
+	for name := range projects {
+		names = append(names, name)
+	}
+	// Allow file completion for commands that accept paths (e.g., start)
+	// but not for commands that only accept project names (e.g., project remove)
+	if cmd.Name() == "remove" {
+		return names, cobra.ShellCompDirectiveNoFileComp
+	}
+	return names, cobra.ShellCompDirectiveDefault
+}

- Check os.UserHomeDir() errors in installBinary/installShellCompletion
- Use io.Copy for streaming binary copy instead of ReadFile
- Reflect install failures in RunInit allGood flag
- Fix ProjectRemoveCmd to use NoFileComp directive
- Add install.ps1 for Windows one-liner install
- Add PowerShell quick install to README
@ourines ourines merged commit be8aa83 into main Feb 10, 2026
2 checks passed
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.

feat: add shell completion support

1 participant