List available targets when incorrect target passed (#756)

## Changes
List available targets when incorrect target passed

## Tests
```
andrew.nester@HFW9Y94129 wheel % databricks bundle validate -t incorrect
Error: incorrect: no such target. Available targets: prod, development
```
This commit is contained in:
Andrew Nester 2023-09-08 17:37:55 +02:00 committed by GitHub
parent 18a5b05d82
commit b5d033d154
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -3,8 +3,10 @@ package mutator
import (
"context"
"fmt"
"strings"
"github.com/databricks/cli/bundle"
"golang.org/x/exp/maps"
)
type selectTarget struct {
@ -30,7 +32,7 @@ func (m *selectTarget) Apply(_ context.Context, b *bundle.Bundle) error {
// Get specified target
target, ok := b.Config.Targets[m.name]
if !ok {
return fmt.Errorf("%s: no such target", m.name)
return fmt.Errorf("%s: no such target. Available targets: %s", m.name, strings.Join(maps.Keys(b.Config.Targets), ", "))
}
// Merge specified target into root configuration structure.

View File

@ -0,0 +1,17 @@
package config_tests
import (
"path/filepath"
"testing"
"github.com/databricks/cli/internal"
"github.com/stretchr/testify/require"
)
func TestSuggestTargetIfWrongPassed(t *testing.T) {
t.Setenv("BUNDLE_ROOT", filepath.Join("target_overrides", "workspace"))
_, _, err := internal.RequireErrorRun(t, "bundle", "validate", "-e", "incorrect")
require.ErrorContains(t, err, "Available targets:")
require.ErrorContains(t, err, "development")
require.ErrorContains(t, err, "staging")
}