Skip to content

Commit

Permalink
Do not load config for the bash completion command
Browse files Browse the repository at this point in the history
When a user is sourcing porter's completion command in their zshrc file
for example, if there is bad config, this causes their entire shell to
not load properly. Also the command doesn't need any configuration so
loading is slow and silly.

Signed-off-by: Carolyn Van Slyck <me@carolynvanslyck.com>
Co-authored-by: Yingrong Zhao <yingrong.zhao@gmail.com>
  • Loading branch information
carolynvs and VinozzZ committed May 17, 2022
1 parent 699cc38 commit f4304a7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cmd/porter/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ For additional details see: https://porter.sh/install#command-completion`,
},
}
cmd.Annotations = map[string]string{
"group": "meta",
"group": "meta",
skipConfig: "",
}
return cmd
}
8 changes: 8 additions & 0 deletions cmd/porter/completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"testing"

"get.porter.sh/porter/pkg/porter"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand All @@ -24,3 +25,10 @@ func TestCompletion(t *testing.T) {
// Test the output of the command contains a specific string for bash.
assert.Contains(t, out.String(), "bash completion for porter")
}

func TestCompletion_SkipConfig(t *testing.T) {
p := porter.NewTestPorter(t)
cmd := buildCompletionCommand(p.Porter)
shouldSkip := shouldSkipConfig(cmd)
require.True(t, shouldSkip, "expected that we skip loading configuration for the completion command")
}

0 comments on commit f4304a7

Please sign in to comment.