Skip to content

Commit

Permalink
[Exporter] Fix interactive selection of services
Browse files Browse the repository at this point in the history
  • Loading branch information
alexott committed Nov 19, 2024
1 parent cfd396c commit d90af9b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
11 changes: 7 additions & 4 deletions exporter/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (ic *importContext) allServicesAndListing() (string, string) {
return strings.Join(maps.Keys(services), ","), strings.Join(maps.Keys(listing), ",")
}

func (ic *importContext) interactivePrompts() {
func (ic *importContext) interactivePrompts() string {
req, _ := http.NewRequest("GET", "/", nil)
for ic.Client.DatabricksClient.Config.Authenticate(req) != nil {
ic.Client.DatabricksClient.Config.Host = askFor("🔑 Databricks Workspace URL:")
Expand All @@ -71,20 +71,23 @@ func (ic *importContext) interactivePrompts() {
}
}

ic.listing = map[string]struct{}{}
keys := maps.Keys(services)
slices.Sort(keys)
enabledServices := map[string]struct{}{}
for _, service := range keys {
resources := services[service]
if !askFlag(fmt.Sprintf("✅ Generate for service `%s` (%s) and related resources?",
service, strings.Join(resources, ","))) {
continue
}
ic.listing[service] = struct{}{}
if service == "mounts" {
ic.mounts = true
}
enabledServices[service] = struct{}{}
}
keys = maps.Keys(enabledServices)
slices.Sort(keys)
return strings.Join(keys, ",")
}

// Run import according to flags
Expand Down Expand Up @@ -164,7 +167,7 @@ func Run(args ...string) error {
return err
}
if !skipInteractive {
ic.interactivePrompts()
configuredListing = ic.interactivePrompts()
}
if len(prefix) > 0 {
ic.prefix = prefix + "_"
Expand Down
3 changes: 2 additions & 1 deletion exporter/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ func TestInteractivePrompts(t *testing.T) {
},
},
}
ic.interactivePrompts()
services := ic.interactivePrompts()
assert.Equal(t, "y", ic.match)
assert.True(t, ic.mounts)
assert.Equal(t, "a,mounts", services)
}

0 comments on commit d90af9b

Please sign in to comment.