Skip to content

feat(completion): auto-detect shell and install when no arg given#64

Merged
p0fi merged 10 commits into
mainfrom
feat/completion-auto-detect
Apr 23, 2026
Merged

feat(completion): auto-detect shell and install when no arg given#64
p0fi merged 10 commits into
mainfrom
feat/completion-auto-detect

Conversation

@p0fi
Copy link
Copy Markdown
Owner

@p0fi p0fi commented Apr 23, 2026

Summary

Closes #58.

  • matter completion (no args) now reads $SHELL, maps it to a supported shell (bash/zsh/fish), and installs completions automatically — no flags needed
  • On Windows, defaults to powershell
  • When detection fails (unset $SHELL or unsupported shell like nushell), the error explicitly names the valid values instead of printing cobra's generic arg-count error
  • matter completion <shell> (explicit, no --install) still prints to stdout — unchanged
  • matter completion <shell> --install still installs explicitly — unchanged

Test plan

  • TestCompletionNoArgs_AutoDetect — bash/zsh/fish each auto-detect and install
  • TestCompletionNoArgs_UnsetShell — empty $SHELL returns helpful error
  • TestCompletionNoArgs_UnsupportedShell — e.g. /bin/nushell returns error naming valid values
  • TestDetectShell — unit tests for all detection cases (valid paths, empty, unsupported)
  • Existing generate/install/idempotent tests still pass

matter completion with no argument now reads $SHELL, maps it to a
supported shell (bash/zsh/fish), and installs completions automatically.
On Windows it defaults to powershell.

When detection fails (unset $SHELL or unsupported shell like nushell)
the error names the valid values explicitly instead of printing cobra's
generic usage error.

Closes #58
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 updates the matter completion command to make no-argument usage behave like an “install completions” workflow by default, using shell auto-detection to remove the current arg-count error and improve first-run ergonomics (closes #58).

Changes:

  • Make the shell argument optional (MaximumNArgs(1)), and when omitted auto-detect the shell and run installation.
  • Add detectShell() to map $SHELL to a supported shell (and default to powershell on Windows) with clearer error messages when detection fails.
  • Expand test coverage for no-arg behavior and shell detection.

Reviewed changes

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

File Description
cli/completion.go Makes completion argument optional, adds shell auto-detection, and installs automatically on no-arg invocation with improved help text.
cli/completion_test.go Adds tests for no-arg auto-detect/install behavior and unit tests for detectShell().

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

Comment thread cli/completion.go
Comment thread cli/completion.go
p0fi and others added 7 commits April 23, 2026 21:18
Ensures Dependabot (and human) PRs can't be merged until gofmt,
golangci-lint, `go test -race` on Ubuntu + macOS, and the build
task all succeed. Also extends Dependabot to track GitHub Actions
versions weekly.
Bumps [jdx/mise-action](https://github.com/jdx/mise-action) from 2 to 4.
- [Release notes](https://github.com/jdx/mise-action/releases)
- [Changelog](https://github.com/jdx/mise-action/blob/main/CHANGELOG.md)
- [Commits](jdx/mise-action@v2...v4)

---
updated-dependencies:
- dependency-name: jdx/mise-action
  dependency-version: '4'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…#55)

Bumps [github.com/charmbracelet/x/term](https://github.com/charmbracelet/x) from 0.2.1 to 0.2.2.
- [Commits](charmbracelet/x@ansi/v0.2.1...ansi/v0.2.2)

---
updated-dependencies:
- dependency-name: github.com/charmbracelet/x/term
  dependency-version: 0.2.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.48.0 to 0.50.0.
- [Commits](golang/crypto@v0.48.0...v0.50.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-version: 0.50.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [tinygo.org/x/bluetooth](https://github.com/tinygo-org/bluetooth) from 0.14.0 to 0.15.0.
- [Release notes](https://github.com/tinygo-org/bluetooth/releases)
- [Changelog](https://github.com/tinygo-org/bluetooth/blob/dev/CHANGELOG.md)
- [Commits](tinygo-org/bluetooth@v0.14.0...v0.15.0)

---
updated-dependencies:
- dependency-name: tinygo.org/x/bluetooth
  dependency-version: 0.15.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [github.com/mattn/go-isatty](https://github.com/mattn/go-isatty) from 0.0.20 to 0.0.21.
- [Commits](mattn/go-isatty@v0.0.20...v0.0.21)

---
updated-dependencies:
- dependency-name: github.com/mattn/go-isatty
  dependency-version: 0.0.21
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…e shell list

- Document in Long/Example that Windows no-arg invocation always uses PowerShell
- Introduce supportedShells var as single source of truth for ValidArgs and detectShell error messages
@p0fi p0fi merged commit 6dc6857 into main Apr 23, 2026
4 checks passed
@p0fi p0fi deleted the feat/completion-auto-detect branch April 23, 2026 19:24
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.

Auto-Detect Shell and Install Completions when No Argument Given

2 participants