Skip to content

Commit

Permalink
fix(cli): env ls should work if not in copilot dir (#1021)
Browse files Browse the repository at this point in the history
<!-- Provide summary of changes -->
Fixes #1004.
<!-- Issue number, if available. E.g. "Fixes #31", "Addresses #42, 77" -->

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
  • Loading branch information
iamhopaul123 committed Jun 15, 2020
1 parent a0fc159 commit 5f24300
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 49 deletions.
11 changes: 0 additions & 11 deletions internal/pkg/cli/env_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,6 @@ func newListEnvOpts(vars listEnvVars) (*listEnvOpts, error) {
}, nil
}

// Validate returns an error if the values passed by flags are invalid.
func (o *listEnvOpts) Validate() error {
if o.AppName() == "" {
return fmt.Errorf("no application found: run %s or %s into your workspace please", color.HighlightCode("app init"), color.HighlightCode("cd"))
}
return nil
}

// Ask asks for fields that are required but not passed in.
func (o *listEnvOpts) Ask() error {
if o.AppName() != "" {
Expand Down Expand Up @@ -135,9 +127,6 @@ func BuildEnvListCmd() *cobra.Command {
if err != nil {
return err
}
if err := opts.Validate(); err != nil {
return err
}
if err := opts.Ask(); err != nil {
return err
}
Expand Down
38 changes: 0 additions & 38 deletions internal/pkg/cli/env_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,6 @@ import (
"github.com/stretchr/testify/require"
)

func TestListEnvOpts_Validate(t *testing.T) {
testCases := map[string]struct {
inAppName string

wantedErr string
}{
"valid app": {
inAppName: "phonetool",
},
"invalid app": {
inAppName: "",

wantedErr: fmt.Sprint("no application found: run `app init` or `cd` into your workspace please"),
},
}

for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
// GIVEN
opts := &initEnvOpts{
initEnvVars: initEnvVars{
GlobalOpts: &GlobalOpts{appName: tc.inAppName},
},
}

// WHEN
err := opts.Validate()

// THEN
if tc.wantedErr != "" {
require.EqualError(t, err, tc.wantedErr)
} else {
require.Nil(t, err)
}
})
}
}

func TestEnvList_Ask(t *testing.T) {
testCases := map[string]struct {
inputApp string
Expand Down

0 comments on commit 5f24300

Please sign in to comment.