Skip to content

Commit

Permalink
chore: fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
adaam2 committed Mar 5, 2025
1 parent 776b943 commit 9d0ed32
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
27 changes: 19 additions & 8 deletions cmd/quickstart.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type QuickstartFlags struct {
Schema string `json:"schema"`
OutDir string `json:"out-dir"`
TargetType string `json:"target"`
Blueprint string `json:"blueprint"`
From string `json:"from"`
}

//go:embed sample_openapi.yaml
Expand Down Expand Up @@ -77,9 +77,9 @@ var quickstartCmd = &model.ExecutableCommand[QuickstartFlags]{
Description: fmt.Sprintf("language to generate sdk for (available options: [%s])", strings.Join(prompts.GetSupportedTargets(), ", ")),
},
flag.StringFlag{
Name: "blueprint",
Shorthand: "b",
Description: "blueprint to use for the quickstart command",
Name: "from",
Shorthand: "f",
Description: "template to use for the quickstart command.\nCreate a new sandbox at https://app.speakeasy.com/sandbox",
},
},
}
Expand All @@ -103,8 +103,6 @@ func quickstartExec(ctx context.Context, flags QuickstartFlags) error {
return ErrWorkflowExists
}

log.From(ctx).PrintfStyled(styles.DimmedItalic, "\nYour first SDK is a few short questions away...\n")

quickstartObj := prompts.Quickstart{
WorkflowFile: &workflow.Workflow{
Version: workflow.WorkflowVersion,
Expand All @@ -122,8 +120,9 @@ func quickstartExec(ctx context.Context, flags QuickstartFlags) error {
quickstartObj.Defaults.TargetType = &flags.TargetType
}

if flags.Blueprint != "" {
quickstartObj.Defaults.Blueprint = &flags.Blueprint
if flags.From != "" {
quickstartObj.Defaults.Blueprint = &flags.From
quickstartObj.IsUsingBlueprint = true
}

nextState := prompts.SourceBase
Expand Down Expand Up @@ -268,6 +267,18 @@ func quickstartExec(ctx context.Context, flags QuickstartFlags) error {
quickstartObj.WorkflowFile.Sources[sourceName].Inputs[0].Location = workflow.LocationString(referencePath)
}

// fooMove the tempfile to the output directory
if quickstartObj.IsUsingBlueprint {
oldInput := quickstartObj.WorkflowFile.Sources[sourceName].Inputs[0].Location

newPath := filepath.Join(outDir, "openapi.yaml")
if err := os.Rename(oldInput.Resolve(), newPath); err != nil {
return errors.Wrapf(err, "failed to rename blueprint to openapi.yaml")
}

quickstartObj.WorkflowFile.Sources[sourceName].Inputs[0].Location = workflow.LocationString(newPath)
}

// Make sure the workflow file stays up to date
run.Migrate(ctx, quickstartObj.WorkflowFile)

Expand Down
6 changes: 3 additions & 3 deletions prompts/sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,14 @@ func sourceBaseForm(ctx context.Context, quickstart *Quickstart) (*QuickstartSta

fmt.Println(
styles.RenderInfoMessage(
fmt.Sprintf("Using blueprint '%s'", *quickstart.Defaults.Blueprint),
fmt.Sprintf("Using sandbox session '%s'", *quickstart.Defaults.Blueprint),
) + "\n",
)
} else {
// fallthrough
fmt.Println(
styles.RenderInfoMessage(
fmt.Sprintf("Blueprint '%s' does not exist. Continuing with quickstart...", *quickstart.Defaults.Blueprint),
fmt.Sprintf("Could not find sandbox session '%s'. Continuing with quickstart...", *quickstart.Defaults.Blueprint),
) + "\n",
)
}
Expand Down Expand Up @@ -718,7 +718,7 @@ func fetchAndSaveBlueprint(ctx context.Context, blueprintID string) (string, err
if err != nil {
return "", ErrMsgFailedToDecodeBlueprint
}
req, err := http.NewRequest("POST", url, bytes.NewBuffer(body))
req, err := http.NewRequest(http.MethodGet, url, bytes.NewBuffer(body))
if err != nil {
return "", ErrMsgFailedToFetchBlueprint
}
Expand Down
1 change: 1 addition & 0 deletions prompts/statemappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Quickstart struct {
LanguageConfigs map[string]*config.Configuration
Defaults Defaults
IsUsingSampleOpenAPISpec bool
IsUsingBlueprint bool
SDKName string
}

Expand Down

0 comments on commit 9d0ed32

Please sign in to comment.