Skip to content

Commit

Permalink
Merge pull request #525 from DefangLabs/lio-fix-generate
Browse files Browse the repository at this point in the history
fix regressions in generate
  • Loading branch information
lionello authored Jul 5, 2024
2 parents 54bf92a + b863e1a commit 3b44b83
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
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

0 comments on commit 3b44b83

Please sign in to comment.