Skip to content

fix regressions in generate #525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 5, 2024
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
2 changes: 2 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ jobs:

build-and-sign:
name: Build app and sign files (with Trusted Signing)
if: startsWith(github.ref, 'refs/tags/v') # only run this step on tagged commits
environment: release # must use environment to be able to authenticate with Azure Federated Identity for Trusted Signing
needs: go-test
runs-on: windows-latest
Expand Down Expand Up @@ -169,6 +170,7 @@ jobs:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

- name: Trusted Signing
uses: Azure/[email protected]
if: startsWith(github.ref, 'refs/tags/v') # only run this step on tagged commits
Expand Down
15 changes: 8 additions & 7 deletions src/cmd/cli/command/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,11 +563,11 @@ var generateCmd = &cobra.Command{

term.Info("Code generated successfully in folder", prompt.Folder)

// TODO: should we use EDITOR env var instead?
cmdd := exec.Command("code", ".")
cmdd := exec.Command("code", prompt.Folder)
err = cmdd.Start()
if err != nil {
term.Debug("unable to launch VS Code:", err)
// TODO: should we use EDITOR env var instead?
}

cd := ""
Expand All @@ -576,15 +576,16 @@ var generateCmd = &cobra.Command{
}

// Load the project and check for empty environment variables
var envInstructions = ""
loader := compose.Loader{ComposeFilePath: filepath.Join(prompt.Folder, "compose.yaml")}
project, _ := loader.LoadCompose(cmd.Context())

envVars := collectUnsetEnvVars(project) // if err != nil -> proj == nil, which is handled in the collectUnsetEnvVars function
envInstructions = strings.Join(envVars, " ")
var envInstructions []string
for _, envVar := range collectUnsetEnvVars(project) {
envInstructions = append(envInstructions, "config create "+envVar)
}

if envInstructions != "" { // logic needs to be duplicated in case where no env vars in yaml file.
printDefangHint("Check the files in your favorite editor.\nTo deploy the service, do "+cd, "config set "+envInstructions)
if len(envInstructions) > 0 {
printDefangHint("Check the files in your favorite editor.\nTo deploy the service, do "+cd, envInstructions...)
} else {
printDefangHint("Check the files in your favorite editor.\nTo deploy the service, do "+cd, "compose up")
}
Expand Down
12 changes: 8 additions & 4 deletions src/cmd/cli/command/hint.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func prettyExecutable(def string) string {
return executable
}

func printDefangHint(hint, args string) {
func printDefangHint(hint string, cmds ...string) {
if pkg.GetenvBool("DEFANG_HIDE_HINTS") || !hasTty {
return
}
Expand All @@ -43,12 +43,16 @@ func printDefangHint(hint, args string) {
fmt.Printf("\n%s\n", hint)
providerFlag := RootCmd.Flag("provider")
clusterFlag := RootCmd.Flag("cluster")
var prefix string
if providerFlag.Changed {
fmt.Printf("\n %s --provider %s %s\n\n", executable, providerFlag.Value.String(), args)
prefix = fmt.Sprintf("%s --provider %s", executable, providerFlag.Value.String())
} else if clusterFlag.Changed {
fmt.Printf("\n %s --cluster %s %s\n\n", executable, clusterFlag.Value.String(), args)
prefix = fmt.Sprintf("%s --cluster %s", executable, clusterFlag.Value.String())
} else {
fmt.Printf("\n %s %s\n\n", executable, args)
prefix = executable
}
for _, arg := range cmds {
fmt.Printf("\n %s %s\n", prefix, arg)
}
if rand.Intn(10) == 0 {
fmt.Println("To silence these hints, do: export DEFANG_HIDE_HINTS=1")
Expand Down