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
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
1 change: 0 additions & 1 deletion cmd/gendoc/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,6 @@ Contains a JSON object with the details of an error.
Path: "/v1/apps",
Request: handlers.CreateAppRequest{},
Parameters: (*struct {
SkipPython bool `query:"skip-python" description:"If true, the app will not be created with the python part."`
SkipSketch bool `query:"skip-sketch" description:"If true, the app will not be created with the sketch part."`
})(nil),
CustomSuccessResponse: &CustomResponseDef{
Expand Down
6 changes: 0 additions & 6 deletions internal/api/docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ paths:
description: Creates a new app in the default app location.
operationId: createApp
parameters:
- description: If true, the app will not be created with the python part.
in: query
name: skip-python
schema:
description: If true, the app will not be created with the python part.
type: boolean
- description: If true, the app will not be created with the sketch part.
in: query
name: skip-sketch
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
19 changes: 0 additions & 19 deletions internal/e2e/client/client.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 0 additions & 30 deletions internal/e2e/daemon/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ func TestCreateApp(t *testing.T) {
{
name: "should return 400 bad request when icon is not a single emoji",
parameters: client.CreateAppParams{
SkipPython: f.Ptr(false),
SkipSketch: f.Ptr(false),
},
body: client.CreateAppRequest{
Expand All @@ -107,7 +106,6 @@ func TestCreateApp(t *testing.T) {
{
name: "should create app successfully when icon is empty",
parameters: client.CreateAppParams{
SkipPython: f.Ptr(false),
SkipSketch: f.Ptr(false),
},
body: client.CreateAppRequest{
Expand All @@ -121,7 +119,6 @@ func TestCreateApp(t *testing.T) {
{
name: "should return 201 Created on first successful creation",
parameters: client.CreateAppParams{
SkipPython: f.Ptr(false),
SkipSketch: f.Ptr(false),
},
body: defaultRequestBody,
Expand All @@ -130,30 +127,15 @@ func TestCreateApp(t *testing.T) {
{
name: "should return 409 Conflict when creating a duplicate app",
parameters: client.CreateAppParams{
SkipPython: f.Ptr(false),
SkipSketch: f.Ptr(false),
},
body: defaultRequestBody,
expectedStatusCode: http.StatusConflict,
expectedErrorDetails: f.Ptr("app already exists"),
},
{
name: "should return 201 Created on successful creation with skip_python",
parameters: client.CreateAppParams{
SkipPython: f.Ptr(true),
SkipSketch: f.Ptr(false),
},
body: client.CreateAppRequest{
Icon: f.Ptr("🌎"),
Name: "HelloWorld_2",
Description: f.Ptr("My HelloWorld_2 description"),
},
expectedStatusCode: http.StatusCreated,
},
{
name: "should return 201 Created on successful creation with skip_sketch",
parameters: client.CreateAppParams{
SkipPython: f.Ptr(false),
SkipSketch: f.Ptr(true),
},
body: client.CreateAppRequest{
Expand All @@ -163,16 +145,6 @@ func TestCreateApp(t *testing.T) {
},
expectedStatusCode: http.StatusCreated,
},
{
name: "should return 400 Bad Request when creating an app with both filters set to true",
parameters: client.CreateAppParams{
SkipPython: f.Ptr(true),
SkipSketch: f.Ptr(true),
},
body: defaultRequestBody,
expectedStatusCode: http.StatusBadRequest,
expectedErrorDetails: f.Ptr("cannot skip both python and sketch"),
},
}

for _, tc := range testCases {
Expand Down Expand Up @@ -985,7 +957,6 @@ func TestAppList(t *testing.T) {
expectedAppNumber := 5
for i := 0; i < expectedAppNumber; i++ {
r, err := httpClient.CreateApp(t.Context(), &client.CreateAppParams{
SkipPython: f.Ptr(false),
SkipSketch: f.Ptr(false),
}, client.CreateAppRequest{
Icon: f.Ptr("🌎"),
Expand All @@ -1003,7 +974,6 @@ func TestAppList(t *testing.T) {

t.Run("AppListDefault_success", func(t *testing.T) {
r, err := httpClient.CreateApp(t.Context(), &client.CreateAppParams{
SkipPython: f.Ptr(false),
SkipSketch: f.Ptr(false),
}, client.CreateAppRequest{
Icon: f.Ptr("🌎"),
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