Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 2 additions & 6 deletions cmd/arduino-app-cli/app/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func newCreateCmd(cfg config.Configuration) *cobra.Command {
icon string
description string
bricks []string
noPyton bool
noSketch bool
fromApp string
)
Expand All @@ -44,22 +43,20 @@ func newCreateCmd(cfg config.Configuration) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
cobra.MinimumNArgs(1)
name := args[0]
return createHandler(cmd.Context(), cfg, name, icon, description, noPyton, noSketch, fromApp)
return createHandler(cmd.Context(), cfg, name, icon, description, noSketch, fromApp)
},
}

cmd.Flags().StringVarP(&icon, "icon", "i", "", "Icon for the app")
cmd.Flags().StringVarP(&description, "description", "d", "", "Description for the app")
cmd.Flags().StringVarP(&fromApp, "from-app", "", "", "Create the new app from the path of an existing app")
cmd.Flags().StringArrayVarP(&bricks, "bricks", "b", []string{}, "List of bricks to include in the app")
cmd.Flags().BoolVarP(&noPyton, "no-python", "", false, "Do not include Python files")
cmd.Flags().BoolVarP(&noSketch, "no-sketch", "", false, "Do not include Sketch files")
cmd.MarkFlagsMutuallyExclusive("no-python", "no-sketch")

return cmd
}

func createHandler(ctx context.Context, cfg config.Configuration, name string, icon string, description string, noPython, noSketch bool, fromApp string) error {
func createHandler(ctx context.Context, cfg config.Configuration, name string, icon string, description string, noSketch bool, fromApp string) error {
if fromApp != "" {
id, err := servicelocator.GetAppIDProvider().ParseID(fromApp)
if err != nil {
Expand Down Expand Up @@ -88,7 +85,6 @@ func createHandler(ctx context.Context, cfg config.Configuration, name string, i
Name: name,
Icon: icon,
Description: description,
SkipPython: noPython,
SkipSketch: noSketch,
}, servicelocator.GetAppIDProvider(), cfg)
if err != nil {
Expand Down
9 changes: 0 additions & 9 deletions internal/api/handlers/app_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,9 @@ func HandleAppCreate(
defer r.Body.Close()

queryParams := r.URL.Query()
skipPythonStr := queryParams.Get("skip-python")
skipSketchStr := queryParams.Get("skip-sketch")

skipPython := queryParamsValidator(skipPythonStr)
skipSketch := queryParamsValidator(skipSketchStr)

if skipPython && skipSketch {
render.EncodeResponse(w, http.StatusBadRequest, models.ErrorResponse{Details: "cannot skip both python and sketch"})
return
}

var req CreateAppRequest
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
slog.Error("unable to decode app create request", slog.String("error", err.Error()))
Expand All @@ -68,7 +60,6 @@ func HandleAppCreate(
Name: req.Name,
Icon: req.Icon,
Description: req.Description,
SkipPython: skipPython,
SkipSketch: skipSketch,
},
idProvider,
Expand Down
23 changes: 5 additions & 18 deletions internal/orchestrator/app/generator/app_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,22 @@ import (

const templateRoot = "app_template"

type Opts int

const (
None Opts = 0
SkipSketch Opts = 1 << iota
SkipPython
)

//go:embed all:app_template
var fsApp embed.FS

func GenerateApp(basePath *paths.Path, app app.AppDescriptor, options Opts) error {
func GenerateApp(basePath *paths.Path, app app.AppDescriptor, skipSketch bool) error {
if err := basePath.MkdirAll(); err != nil {
return fmt.Errorf("failed to create app directory: %w", err)
}
isSkipSketchSet := options&SkipSketch != 0
isSkipPythonSet := options&SkipPython != 0

if !isSkipSketchSet {
if !skipSketch {
if err := generateSketch(basePath); err != nil {
return fmt.Errorf("failed to create sketch: %w", err)
}
}
if !isSkipPythonSet {
if err := generatePython(basePath); err != nil {
return fmt.Errorf("failed to create python: %w", err)
}
}

if err := generatePython(basePath); err != nil {
return fmt.Errorf("failed to create python: %w", err)
}
if err := generateApp(basePath, app); err != nil {
return fmt.Errorf("failed to create app.yaml: %w", err)
}
Expand Down
12 changes: 3 additions & 9 deletions internal/orchestrator/app/generator/app_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,25 @@ func TestGenerateApp(t *testing.T) {

testCases := []struct {
name string
options Opts
skipSketch bool
goldenPath string
}{
{
name: "generate complete app",
options: None,
goldenPath: "testdata/app-all.golden",
},
{
name: "skip sketch",
options: SkipSketch,
skipSketch: true,
goldenPath: "testdata/app-no-sketch.golden",
},
{
name: "skip python",
options: SkipPython,
goldenPath: "testdata/app-no-python.golden",
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
tempDir := t.TempDir()

err := GenerateApp(paths.New(tempDir), baseApp, tc.options)
err := GenerateApp(paths.New(tempDir), baseApp, tc.skipSketch)
require.NoError(t, err)

if os.Getenv("UPDATE_GOLDEN") == "true" {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

14 changes: 1 addition & 13 deletions internal/orchestrator/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,6 @@ type CreateAppRequest struct {
Name string
Icon string
Description string
SkipPython bool
SkipSketch bool
}

Expand All @@ -763,9 +762,6 @@ func CreateApp(
idProvider *app.IDProvider,
cfg config.Configuration,
) (CreateAppResponse, error) {
if req.SkipPython && req.SkipSketch {
return CreateAppResponse{}, fmt.Errorf("cannot skip both python and sketch")
}
if req.Name == "" {
return CreateAppResponse{}, fmt.Errorf("app name cannot be empty")
}
Expand All @@ -784,16 +780,8 @@ func CreateApp(
if err := newApp.IsValid(); err != nil {
return CreateAppResponse{}, fmt.Errorf("%w: %v", app.ErrInvalidApp, err)
}
var options appgenerator.Opts = 0

if req.SkipSketch {
options |= appgenerator.SkipSketch
}
if req.SkipPython {
options |= appgenerator.SkipPython
}

if err := appgenerator.GenerateApp(basePath, newApp, options); err != nil {
if err := appgenerator.GenerateApp(basePath, newApp, req.SkipSketch); err != nil {
return CreateAppResponse{}, fmt.Errorf("failed to create app: %w", err)
}
id, err := idProvider.IDFromPath(basePath)
Expand Down
Loading