Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"flag"
"fmt"
"io"
"maps"
"net/http"
"os"
"os/exec"
Expand All @@ -31,7 +32,6 @@ import (
"github.com/databricks/cli/libs/auth"
"github.com/databricks/cli/libs/testdiff"
"github.com/databricks/cli/libs/testserver"
"github.com/databricks/cli/libs/utils"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -817,7 +817,7 @@ func buildTestEnv(configEnv map[string]string, customEnv []string) []string {
env := make([]string, 0, len(configEnv)+len(customEnv))

// Add config.Env first (but skip keys that exist in customEnv)
for _, key := range utils.SortedKeys(configEnv) {
for _, key := range slices.Sorted(maps.Keys(configEnv)) {
if hasKey(customEnv, key) {
continue
}
Expand Down
7 changes: 2 additions & 5 deletions acceptance/internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package internal

import (
"hash/fnv"
"maps"
"os"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -345,11 +346,7 @@ func ExpandEnvMatrix(matrix, exclude map[string][]string, extraVars []string) []
return result
}

keys := make([]string, 0, len(filteredMatrix))
for key := range filteredMatrix {
keys = append(keys, key)
}
slices.Sort(keys)
keys := slices.Sorted(maps.Keys(filteredMatrix))

// Build an expansion of all combinations.
// At each step we look at a given key and append each possible value to each
Expand Down
5 changes: 3 additions & 2 deletions bundle/artifacts/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package artifacts
import (
"context"
"fmt"
"maps"
"os"
"path/filepath"
"slices"

"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/config"
Expand All @@ -15,7 +17,6 @@ import (
"github.com/databricks/cli/libs/log"
"github.com/databricks/cli/libs/logdiag"
"github.com/databricks/cli/libs/patchwheel"
"github.com/databricks/cli/libs/utils"
)

func Build() bundle.Mutator {
Expand All @@ -37,7 +38,7 @@ func (m *build) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
})
}

for _, artifactName := range utils.SortedKeys(b.Config.Artifacts) {
for _, artifactName := range slices.Sorted(maps.Keys(b.Config.Artifacts)) {
a := b.Config.Artifacts[artifactName]

if a.BuildCommand != "" {
Expand Down
5 changes: 3 additions & 2 deletions bundle/artifacts/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package artifacts
import (
"context"
"errors"
"maps"
"os"
"path/filepath"
"slices"

"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/config"
Expand All @@ -15,7 +17,6 @@ import (
"github.com/databricks/cli/libs/log"
"github.com/databricks/cli/libs/logdiag"
"github.com/databricks/cli/libs/python"
"github.com/databricks/cli/libs/utils"
)

func Prepare() bundle.Mutator {
Expand All @@ -34,7 +35,7 @@ func (m *prepare) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics
return diag.FromErr(err)
}

for _, artifactName := range utils.SortedKeys(b.Config.Artifacts) {
for _, artifactName := range slices.Sorted(maps.Keys(b.Config.Artifacts)) {
artifact := b.Config.Artifacts[artifactName]
if artifact == nil {
l := b.Config.GetLocation("artifacts." + artifactName)
Expand Down
5 changes: 3 additions & 2 deletions bundle/config/validate/scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package validate
import (
"context"
"fmt"
"maps"
"regexp"
"slices"

"github.com/databricks/cli/bundle"
"github.com/databricks/cli/libs/diag"
"github.com/databricks/cli/libs/dyn"
"github.com/databricks/cli/libs/utils"
)

type validateScripts struct{}
Expand All @@ -28,7 +29,7 @@ func (f *validateScripts) Apply(ctx context.Context, b *bundle.Bundle) diag.Diag

// Sort the scripts to have a deterministic order for the
// generated diagnostics.
scriptKeys := utils.SortedKeys(b.Config.Scripts)
scriptKeys := slices.Sorted(maps.Keys(b.Config.Scripts))

for _, k := range scriptKeys {
script := b.Config.Scripts[k]
Expand Down
13 changes: 3 additions & 10 deletions bundle/configsync/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package configsync

import (
"fmt"
"maps"
"slices"
"strings"
)
Expand All @@ -17,21 +18,13 @@ func FormatTextOutput(changes Changes) string {

output.WriteString(fmt.Sprintf("Detected changes in %d resource(s):\n\n", len(changes)))

resourceKeys := make([]string, 0, len(changes))
for key := range changes {
resourceKeys = append(resourceKeys, key)
}
slices.Sort(resourceKeys)
resourceKeys := slices.Sorted(maps.Keys(changes))

for _, resourceKey := range resourceKeys {
resourceChanges := changes[resourceKey]
output.WriteString(fmt.Sprintf("Resource: %s\n", resourceKey))

paths := make([]string, 0, len(resourceChanges))
for path := range resourceChanges {
paths = append(paths, path)
}
slices.Sort(paths)
paths := slices.Sorted(maps.Keys(resourceChanges))

for _, path := range paths {
configChange := resourceChanges[path]
Expand Down
7 changes: 2 additions & 5 deletions bundle/configsync/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"fmt"
"io/fs"
"maps"
"path/filepath"
"slices"
"strings"
Expand Down Expand Up @@ -171,11 +172,7 @@ func ResolveChanges(ctx context.Context, b *bundle.Bundle, configChanges Changes
var result []FieldChange
targetName := b.Config.Bundle.Target

resourceKeys := make([]string, 0, len(configChanges))
for resourceKey := range configChanges {
resourceKeys = append(resourceKeys, resourceKey)
}
slices.Sort(resourceKeys)
resourceKeys := slices.Sorted(maps.Keys(configChanges))

for _, resourceKey := range resourceKeys {
resourceChanges := configChanges[resourceKey]
Expand Down
3 changes: 1 addition & 2 deletions bundle/direct/bundle_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/databricks/cli/libs/structs/structdiff"
"github.com/databricks/cli/libs/structs/structpath"
"github.com/databricks/cli/libs/structs/structvar"
"github.com/databricks/cli/libs/utils"
"github.com/databricks/databricks-sdk-go"
)

Expand Down Expand Up @@ -968,7 +967,7 @@ func (b *DeploymentBundle) getAdapterForKey(resourceKey string) (*dresources.Ada

adapter, ok := b.Adapters[group]
if !ok {
return nil, fmt.Errorf("resource type %q not supported, available: %s", group, strings.Join(utils.SortedKeys(b.Adapters), ", "))
return nil, fmt.Errorf("resource type %q not supported, available: %s", group, strings.Join(slices.Sorted(maps.Keys(b.Adapters)), ", "))
}

return adapter, nil
Expand Down
5 changes: 3 additions & 2 deletions bundle/direct/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ package direct

import (
"fmt"
"maps"
"slices"

"github.com/databricks/cli/bundle/deployplan"
"github.com/databricks/cli/libs/dagrun"
"github.com/databricks/cli/libs/utils"
)

func makeGraph(plan *deployplan.Plan) (*dagrun.Graph, error) {
g := dagrun.NewGraph()

// Add all nodes first
for _, resourceKey := range utils.SortedKeys(plan.Plan) {
for _, resourceKey := range slices.Sorted(maps.Keys(plan.Plan)) {
g.AddNode(resourceKey)
}

Expand Down
8 changes: 2 additions & 6 deletions bundle/internal/schema/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"bytes"
"fmt"
"maps"
"os"
"reflect"
"regexp"
Expand Down Expand Up @@ -183,12 +184,7 @@ func saveYamlWithStyle(outputPath string, annotations annotation.File) error {
}

func getAlphabeticalOrder[T any](mapping map[string]T) *yamlsaver.Order {
var order []string
for k := range mapping {
order = append(order, k)
}
slices.Sort(order)
return yamlsaver.NewOrder(order)
return yamlsaver.NewOrder(slices.Sorted(maps.Keys(mapping)))
}

func convertLinksToAbsoluteUrl(s string) string {
Expand Down
6 changes: 4 additions & 2 deletions bundle/internal/tf/codegen/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"context"
"fmt"
"log"
"maps"
"os"
"path/filepath"
"slices"
"strings"
"text/template"

Expand Down Expand Up @@ -56,7 +58,7 @@ func (r *root) Generate(path string) error {
func Run(ctx context.Context, schema *tfjson.ProviderSchema, checksums *schemapkg.ProviderChecksums, path string) error {
// Generate types for resources
var resources []*namedBlock
for _, k := range sortKeys(schema.ResourceSchemas) {
for _, k := range slices.Sorted(maps.Keys(schema.ResourceSchemas)) {
// Skipping all plugin framework struct generation.
// TODO: This is a temporary fix, generation should be fixed in the future.
if strings.HasSuffix(k, "_pluginframework") {
Expand Down Expand Up @@ -87,7 +89,7 @@ func Run(ctx context.Context, schema *tfjson.ProviderSchema, checksums *schemapk

// Generate types for data sources.
var dataSources []*namedBlock
for _, k := range sortKeys(schema.DataSourceSchemas) {
for _, k := range slices.Sorted(maps.Keys(schema.DataSourceSchemas)) {
// Skipping all plugin framework struct generation.
// TODO: This is a temporary fix, generation should be fixed in the future.
if strings.HasSuffix(k, "_pluginframework") {
Expand Down
13 changes: 0 additions & 13 deletions bundle/internal/tf/codegen/generator/util.go

This file was deleted.

5 changes: 3 additions & 2 deletions bundle/internal/tf/codegen/generator/walker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package generator

import (
"fmt"
"maps"
"slices"
"strings"

Expand Down Expand Up @@ -117,7 +118,7 @@ func processAttributeType(typ cty.Type, resourceName, attributePath string) stri
}

func nestedBlockKeys(block *tfjson.SchemaBlock) []string {
keys := sortKeys(block.NestedBlocks)
keys := slices.Sorted(maps.Keys(block.NestedBlocks))

// Remove TF specific "timeouts" block.
if i := slices.Index(keys, "timeouts"); i != -1 {
Expand Down Expand Up @@ -163,7 +164,7 @@ func (w *walker) walk(block *tfjson.SchemaBlock, name []string) error {
}

// Declare attributes.
for _, k := range sortKeys(block.Attributes) {
for _, k := range slices.Sorted(maps.Keys(block.Attributes)) {
v := block.Attributes[k]

// Assert the attribute type is always set.
Expand Down
7 changes: 2 additions & 5 deletions bundle/internal/validation/enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"go/format"
"maps"
"os"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -182,11 +183,7 @@ func filterTargetsAndEnvironmentsEnum(patterns map[string][]EnumPatternInfo) map
// sortGroupedPatterns sorts patterns within each group and returns them as a sorted slice
func sortGroupedPatternsEnum(groupedPatterns map[string][]EnumPatternInfo) [][]EnumPatternInfo {
// Get sorted group keys
groupKeys := make([]string, 0, len(groupedPatterns))
for key := range groupedPatterns {
groupKeys = append(groupKeys, key)
}
slices.Sort(groupKeys)
groupKeys := slices.Sorted(maps.Keys(groupedPatterns))

// Build sorted result
result := make([][]EnumPatternInfo, 0, len(groupKeys))
Expand Down
7 changes: 2 additions & 5 deletions bundle/internal/validation/required.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"cmp"
"fmt"
"go/format"
"maps"
"os"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -138,11 +139,7 @@ func filterTargetsAndEnvironments(patterns map[string][]RequiredPatternInfo) map
// sortGroupedPatterns sorts patterns within each group and returns them as a sorted slice
func sortGroupedPatterns(groupedPatterns map[string][]RequiredPatternInfo) [][]RequiredPatternInfo {
// Get sorted group keys
groupKeys := make([]string, 0, len(groupedPatterns))
for key := range groupedPatterns {
groupKeys = append(groupKeys, key)
}
slices.Sort(groupKeys)
groupKeys := slices.Sorted(maps.Keys(groupedPatterns))

// Build sorted result
result := make([][]RequiredPatternInfo, 0, len(groupKeys))
Expand Down
5 changes: 3 additions & 2 deletions bundle/libraries/remote_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package libraries
import (
"context"
"fmt"
"maps"
"path"
"path/filepath"
"slices"

"github.com/databricks/cli/bundle"
"github.com/databricks/cli/libs/diag"
"github.com/databricks/cli/libs/dyn"
"github.com/databricks/cli/libs/utils"
)

// ReplaceWithRemotePath updates all the libraries paths to point to the remote location
Expand All @@ -25,7 +26,7 @@ func ReplaceWithRemotePath(ctx context.Context, b *bundle.Bundle) (map[string][]
return nil, diag.FromErr(err)
}

sources := utils.SortedKeys(libs)
sources := slices.Sorted(maps.Keys(libs))

// Update all the config paths to point to the uploaded location
err = b.Config.Mutate(func(v dyn.Value) (dyn.Value, error) {
Expand Down
Loading
Loading