-
Notifications
You must be signed in to change notification settings - Fork 4
feat(completion): add completion install subcommand and wire it into installer.sh / npm #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: cli-126-distribute-cli-via-npm
Are you sure you want to change the base?
Changes from all commits
7c76350
568d34e
d795950
dd3d7c1
c9598ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| internal/legacy/archives/* | ||
| dist/ | ||
| npm/dist/ | ||
| php-* | ||
| completion | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package commands | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestDetectShell(t *testing.T) { | ||
| cases := []struct { | ||
| shell string | ||
| want string | ||
| }{ | ||
| {"/bin/bash", "bash"}, | ||
| {"/usr/local/bin/zsh", "zsh"}, | ||
| {"/usr/bin/fish", ""}, | ||
| {"", ""}, | ||
| } | ||
| for _, c := range cases { | ||
| t.Run(c.shell, func(t *testing.T) { | ||
| t.Setenv("SHELL", c.shell) | ||
| assert.Equal(t, c.want, detectShell()) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestDefaultCompletionPath(t *testing.T) { | ||
| if os.Geteuid() == 0 { | ||
| t.Skip("non-root user paths only") | ||
| } | ||
|
Comment on lines
+29
to
+32
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as the reply on The |
||
| home := t.TempDir() | ||
| t.Setenv("HOME", home) | ||
| t.Setenv("XDG_DATA_HOME", "") | ||
|
|
||
| cases := []struct { | ||
| shell string | ||
| want string | ||
| }{ | ||
| {"bash", filepath.Join(home, ".local", "share", "bash-completion", "completions", "upsun")}, | ||
| {"zsh", filepath.Join(home, ".zsh", "completions", "_upsun")}, | ||
| } | ||
| for _, c := range cases { | ||
| t.Run(c.shell, func(t *testing.T) { | ||
| got, err := defaultCompletionPath("upsun", c.shell) | ||
| assert.NoError(t, err) | ||
| assert.Equal(t, c.want, got) | ||
| }) | ||
| } | ||
|
|
||
| t.Run("xdg override", func(t *testing.T) { | ||
| xdg := filepath.Join(home, "xdg") | ||
| t.Setenv("XDG_DATA_HOME", xdg) | ||
| got, err := defaultCompletionPath("upsun", "bash") | ||
| assert.NoError(t, err) | ||
| assert.Equal(t, filepath.Join(xdg, "bash-completion", "completions", "upsun"), got) | ||
| }) | ||
|
|
||
| t.Run("unsupported shell", func(t *testing.T) { | ||
| _, err := defaultCompletionPath("upsun", "fish") | ||
| assert.Error(t, err) | ||
| }) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
os.Geteuid()is implemented on Windows — it returns -1 (seesyscall.Geteuidon Windows). Verified by building this package withGOOS=windows GOEXPERIMENT=jsonv2 go build ./...and compiling the test binary withgo test -c; both succeed.Returning -1 means the comparison
Geteuid() == 0is false on Windows, so we already fall through to the user-level path selection — i.e. Windows is already treated as non-root, which matches the recommendation in this comment.