Skip to content

Commit f1fdd8f

Browse files
authored
Collect interpolated vars (#862)
* Collect interpolated vars * Update src/cmd/cli/command/collectUnsetEnvVars_test.go
1 parent 920b036 commit f1fdd8f

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

src/cmd/cli/command/collectUnsetEnvVars_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,20 @@ func TestCollectUnsetEnvVars(t *testing.T) {
149149
},
150150
expected: []string{"config", "CONFIG"},
151151
},
152+
{
153+
name: "Service with interpolated var",
154+
project: &types.Project{
155+
Services: map[string]types.ServiceConfig{
156+
"service1": {
157+
Name: "service1",
158+
Environment: types.MappingWithEquals{
159+
"ENV1": stringPtr("${ENV2}"),
160+
},
161+
},
162+
},
163+
},
164+
expected: []string{"ENV2"},
165+
},
152166
}
153167

154168
for _, tt := range tests {

src/cmd/cli/command/commands.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -608,19 +608,17 @@ var newCmd = &cobra.Command{
608608
}
609609

610610
func collectUnsetEnvVars(project *composeTypes.Project) []string {
611-
var envVars []string
612-
if project != nil {
613-
for _, service := range project.Services {
614-
for key, value := range service.Environment {
615-
if value == nil {
616-
envVars = append(envVars, key)
617-
}
618-
}
619-
}
611+
if project == nil {
612+
return nil // in case loading failed
620613
}
621-
// Deduplicate by sorting and then compacting (uniq)
622-
slices.Sort(envVars)
623-
return slices.Compact(envVars)
614+
err := compose.ValidateProjectConfig(context.TODO(), project, func(ctx context.Context) ([]string, error) {
615+
return nil, nil // assume no config
616+
})
617+
var missingConfig compose.ErrMissingConfig
618+
if errors.As(err, &missingConfig) {
619+
return missingConfig
620+
}
621+
return nil
624622
}
625623

626624
var getVersionCmd = &cobra.Command{

src/pkg/cli/client/playground.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ func (g *PlaygroundProvider) Destroy(ctx context.Context, req *defangv1.DestroyR
7878
for _, service := range servicesList.Services {
7979
names = append(names, service.Service.Name)
8080
}
81+
82+
// FIXME: use Destroy rpc instead of Delete rpc
8183
resp, err := g.Delete(ctx, &defangv1.DeleteRequest{Project: req.Project, Names: names})
8284
if err != nil {
8385
return "", err

0 commit comments

Comments
 (0)