Skip to content

Commit fa9278e

Browse files
committed
fixed generating to different source folder
1 parent e31306a commit fa9278e

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

cmd/bundle/generate/app.go

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"fmt"
77
"io"
88
"io/fs"
9-
"os"
109
"path/filepath"
1110

1211
"github.com/databricks/cli/bundle/config/generate"
@@ -37,13 +36,8 @@ func NewGenerateAppCommand() *cobra.Command {
3736
cmd.Flags().StringVar(&appName, "existing-app-name", "", `App name to generate config for`)
3837
cmd.MarkFlagRequired("existing-app-name")
3938

40-
wd, err := os.Getwd()
41-
if err != nil {
42-
wd = "."
43-
}
44-
45-
cmd.Flags().StringVarP(&configDir, "config-dir", "d", filepath.Join(wd, "resources"), `Directory path where the output bundle config will be stored`)
46-
cmd.Flags().StringVarP(&sourceDir, "source-dir", "s", filepath.Join(wd, "src", "app"), `Directory path where the app files will be stored`)
39+
cmd.Flags().StringVarP(&configDir, "config-dir", "d", filepath.Join("resources"), `Directory path where the output bundle config will be stored`)
40+
cmd.Flags().StringVarP(&sourceDir, "source-dir", "s", filepath.Join("src", "app"), `Directory path where the app files will be stored`)
4741
cmd.Flags().BoolVarP(&force, "force", "f", false, `Force overwrite existing files in the output directory`)
4842

4943
cmd.RunE = func(cmd *cobra.Command, args []string) error {
@@ -60,17 +54,35 @@ func NewGenerateAppCommand() *cobra.Command {
6054
return err
6155
}
6256

57+
// Making sure the config directory and source directory are absolute paths.
58+
if !filepath.IsAbs(configDir) {
59+
configDir = filepath.Join(b.BundleRootPath, configDir)
60+
}
61+
62+
if !filepath.IsAbs(sourceDir) {
63+
sourceDir = filepath.Join(b.BundleRootPath, sourceDir)
64+
}
65+
6366
downloader := newDownloader(w, sourceDir, configDir)
6467

6568
sourceCodePath := app.DefaultSourceCodePath
66-
downloader.markDirectoryForDownload(ctx, &sourceCodePath)
69+
err = downloader.markDirectoryForDownload(ctx, &sourceCodePath)
70+
if err != nil {
71+
return err
72+
}
6773

6874
appConfig, err := getAppConfig(ctx, app, w)
6975
if err != nil {
7076
return fmt.Errorf("failed to get app config: %w", err)
7177
}
7278

73-
v, err := generate.ConvertAppToValue(app, sourceCodePath, appConfig)
79+
// Making sure the source code path is relative to the config directory.
80+
rel, err := filepath.Rel(configDir, sourceDir)
81+
if err != nil {
82+
return err
83+
}
84+
85+
v, err := generate.ConvertAppToValue(app, filepath.ToSlash(rel), appConfig)
7486
if err != nil {
7587
return err
7688
}

0 commit comments

Comments
 (0)