diff --git a/CHANGELOG.md b/CHANGELOG.md index b9b2011d..f99da308 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Bugs * Fix bug where JsonStore was not being created #612 + * Fix fish shell completion ### New Features diff --git a/internal/helper/aws-sso.fish b/internal/helper/aws-sso.fish index e6d62e4a..e27a0f8a 100644 --- a/internal/helper/aws-sso.fish +++ b/internal/helper/aws-sso.fish @@ -4,3 +4,4 @@ function __complete_aws-sso and set COMP_LINE "$COMP_LINE " {{ .Executable }} end +complete -f -c aws-sso -a "(__complete_aws-sso)" diff --git a/internal/utils/fileedit.go b/internal/utils/fileedit.go index ccc467ca..d78c7a9d 100644 --- a/internal/utils/fileedit.go +++ b/internal/utils/fileedit.go @@ -115,6 +115,10 @@ func (f *FileEdit) GenerateNewFile(configFile string) ([]byte, error) { // read & write up to the prefix input, err := os.Open(configFile) if err != nil { + if err = EnsureDirExists(configFile); err != nil { + return []byte{}, err + } + input, err = os.Create(configFile) if err != nil { return []byte{}, err diff --git a/internal/utils/fileedit_test.go b/internal/utils/fileedit_test.go index 63afea77..c4ef3897 100644 --- a/internal/utils/fileedit_test.go +++ b/internal/utils/fileedit_test.go @@ -60,8 +60,25 @@ func TestFileEdit(t *testing.T) { assert.Equal(t, []byte( fmt.Sprintf(FILE_TEMPLATE, CONFIG_PREFIX, "foo", CONFIG_SUFFIX)), fBytes) - // can't open file - err = fe.UpdateConfig(false, true, "/this/directory/and/the/file/in/it/doesn't/exist") + // create the base path + badfile := "./this/doesnt/exist" + err = fe.UpdateConfig(false, true, badfile) + assert.NoError(t, err) + defer os.Remove(badfile) + + // can't treat a file like a directory though :) + baddir := "./thisdoesntwork" + err = os.Mkdir(baddir, 0400) // need read access to pass EnsureDirExists() + assert.NoError(t, err) + defer func() { + os.Chmod(baddir, 0777) + os.Remove(baddir) + }() + err = fe.UpdateConfig(false, true, fmt.Sprintf("%s/foo", baddir)) + assert.Error(t, err) + + // can't create this path + err = fe.UpdateConfig(false, true, "/cant/write/to/root/filesystem") assert.Error(t, err) // setup logger for testing