Skip to content

Commit

Permalink
fix: devcontainer config file name validation (#714)
Browse files Browse the repository at this point in the history
Signed-off-by: Rohan Sharma <[email protected]>
  • Loading branch information
RS-labhub authored Jun 28, 2024
1 parent 583c0ab commit f3e19fc
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions pkg/views/workspace/create/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package create
import (
"errors"
"log"
"path/filepath"

"github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/huh"
Expand Down Expand Up @@ -145,6 +146,14 @@ func ConfigureProjects(projectList *[]apiclient.CreateWorkspaceRequestProject, d
return ConfigureProjects(projectList, defaults)
}

func validateDevcontainerFilename(filename string) error {
baseName := filepath.Base(filename)
if baseName != "devcontainer.json" && baseName != ".devcontainer.json" {
return errors.New("filename must be devcontainer.json or .devcontainer.json")
}
return nil
}

func GetProjectConfigurationForm(projectConfiguration *ProjectConfigurationData) *huh.Form {
buildOptions := []huh.Option[string]{
{Key: "Automatic", Value: string(AUTOMATIC)},
Expand Down Expand Up @@ -175,12 +184,7 @@ func GetProjectConfigurationForm(projectConfiguration *ProjectConfigurationData)
huh.NewGroup(
huh.NewInput().
Title("Devcontainer file path").
Value(&projectConfiguration.DevcontainerFilePath).Validate(func(s string) error {
if s == "" {
return errors.New("devcontainer file path is required")
}
return nil
}),
Value(&projectConfiguration.DevcontainerFilePath).Validate(validateDevcontainerFilename),
).WithHideFunc(func() bool {
return projectConfiguration.BuildChoice != string(DEVCONTAINER)
}),
Expand Down

0 comments on commit f3e19fc

Please sign in to comment.