-
Notifications
You must be signed in to change notification settings - Fork 789
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'DeedleFake-completions-fs'
- Loading branch information
Showing
20 changed files
with
95 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Package completions handles shell completion files. | ||
// | ||
// To add completion support for a shell, simply add a file named | ||
// "asdf.<shell>" to this directory, replacing "<shell>" with the name | ||
// of the shell. | ||
package completions | ||
|
||
import ( | ||
"embed" | ||
"errors" | ||
"io/fs" | ||
"slices" | ||
"strings" | ||
) | ||
|
||
//go:embed asdf.* | ||
var completions embed.FS | ||
|
||
// Get returns a file containing completion code for the given shell if it is | ||
// found. | ||
func Get(name string) (fs.File, bool) { | ||
file, err := completions.Open("asdf." + name) | ||
if err != nil { | ||
if errors.Is(err, fs.ErrNotExist) { | ||
return nil, false | ||
} | ||
panic(err) // This should never happen. | ||
} | ||
return file, true | ||
} | ||
|
||
// Names returns a slice of shell names that completion is available for. | ||
func Names() []string { | ||
files, _ := fs.Glob(completions, "asdf.*") | ||
for i, file := range files { | ||
files[i] = strings.TrimPrefix(file, "asdf.") | ||
} | ||
slices.Sort(files) | ||
return files | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package completions | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGet(t *testing.T) { | ||
t.Run("returns file when completion file found with matching name", func(t *testing.T) { | ||
file, found := Get("bash") | ||
|
||
info, err := file.Stat() | ||
assert.Nil(t, err) | ||
assert.Equal(t, "asdf.bash", info.Name()) | ||
|
||
assert.True(t, found) | ||
}) | ||
|
||
t.Run("returns false when completion file not found", func(t *testing.T) { | ||
_, found := Get("non-existent") | ||
assert.False(t, found) | ||
}) | ||
} | ||
|
||
func TestNames(t *testing.T) { | ||
t.Run("returns slice of shell names for which completion is available", func(t *testing.T) { | ||
assert.Equal(t, []string{"bash", "elvish", "fish", "nushell", "zsh"}, Names()) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters