Skip to content

Commit 433c936

Browse files
committed
fix: manifest load from local template path
1 parent ed6f73f commit 433c936

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

cmd/apps/init_test.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/databricks/cli/libs/apps/manifest"
1212
"github.com/databricks/cli/libs/apps/prompt"
13+
"github.com/databricks/cli/libs/env"
1314
"github.com/spf13/cobra"
1415
"github.com/stretchr/testify/assert"
1516
"github.com/stretchr/testify/require"
@@ -642,8 +643,7 @@ func TestRunManifestOnlyFound(t *testing.T) {
642643
var buf bytes.Buffer
643644
_, _ = io.Copy(&buf, r)
644645
out := buf.String()
645-
assert.Contains(t, out, `"version": "1.0"`)
646-
assert.Contains(t, out, `"analytics"`)
646+
assert.Equal(t, content, out)
647647
}
648648

649649
func TestRunManifestOnlyNotFound(t *testing.T) {
@@ -664,3 +664,26 @@ func TestRunManifestOnlyNotFound(t *testing.T) {
664664
out := buf.String()
665665
assert.Equal(t, "No appkit.plugins.json manifest found in this template.\n", out)
666666
}
667+
668+
func TestRunManifestOnlyUsesTemplatePathEnvVar(t *testing.T) {
669+
dir := t.TempDir()
670+
manifestPath := filepath.Join(dir, manifest.ManifestFileName)
671+
content := `{"version":"1.0","scaffolding":{"command":"databricks apps init"}}`
672+
require.NoError(t, os.WriteFile(manifestPath, []byte(content), 0o644))
673+
674+
old := os.Stdout
675+
r, w, err := os.Pipe()
676+
require.NoError(t, err)
677+
os.Stdout = w
678+
679+
ctx := env.Set(t.Context(), templatePathEnvVar, dir)
680+
err = runManifestOnly(ctx, "", "", "")
681+
w.Close()
682+
os.Stdout = old
683+
require.NoError(t, err)
684+
685+
var buf bytes.Buffer
686+
_, _ = io.Copy(&buf, r)
687+
out := buf.String()
688+
assert.Equal(t, content, out)
689+
}

cmd/apps/manifest.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package apps
22

33
import (
44
"context"
5-
"encoding/json"
65
"errors"
76
"fmt"
87
"os"
@@ -55,15 +54,15 @@ func runManifestOnly(ctx context.Context, templatePath, branch, version string)
5554
}
5655

5756
if manifest.HasManifest(templateDir) {
58-
m, err := manifest.Load(templateDir)
57+
path := filepath.Join(templateDir, manifest.ManifestFileName)
58+
data, err := os.ReadFile(path)
5959
if err != nil {
60-
return fmt.Errorf("load manifest: %w", err)
60+
return fmt.Errorf("read manifest: %w", err)
6161
}
62-
enc, err := json.MarshalIndent(m, "", " ")
62+
_, err = os.Stdout.Write(data)
6363
if err != nil {
64-
return fmt.Errorf("encode manifest: %w", err)
64+
return fmt.Errorf("write manifest: %w", err)
6565
}
66-
fmt.Fprintln(os.Stdout, string(enc))
6766
return nil
6867
}
6968

@@ -83,7 +82,7 @@ func newManifestCmd() *cobra.Command {
8382
Short: "Print template manifest with available plugins and required resources",
8483
Hidden: true,
8584
Long: `Resolves a template (default AppKit repo or --template URL), locates appkit.plugins.json,
86-
and prints its contents to stdout. No workspace authentication is required.
85+
and prints its raw contents to stdout. No workspace authentication is required.
8786
8887
Use the same --template, --branch, and --version flags as "databricks apps init" to target
8988
a specific template. Without --template, uses the default AppKit template (main branch).

0 commit comments

Comments
 (0)