mirror of https://github.com/databricks/cli.git
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:
parent
18a5b05d82
commit
b5d033d154
|
@ -3,8 +3,10 @@ package mutator
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/databricks/cli/bundle"
|
"github.com/databricks/cli/bundle"
|
||||||
|
"golang.org/x/exp/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
type selectTarget struct {
|
type selectTarget struct {
|
||||||
|
@ -30,7 +32,7 @@ func (m *selectTarget) Apply(_ context.Context, b *bundle.Bundle) error {
|
||||||
// Get specified target
|
// Get specified target
|
||||||
target, ok := b.Config.Targets[m.name]
|
target, ok := b.Config.Targets[m.name]
|
||||||
if !ok {
|
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.
|
// Merge specified target into root configuration structure.
|
||||||
|
|
|
@ -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")
|
||||||
|
}
|
Loading…
Reference in New Issue