Skip to content
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
27 changes: 25 additions & 2 deletions cmd/apps/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/databricks/cli/libs/apps/manifest"
"github.com/databricks/cli/libs/apps/prompt"
"github.com/databricks/cli/libs/env"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -642,8 +643,7 @@ func TestRunManifestOnlyFound(t *testing.T) {
var buf bytes.Buffer
_, _ = io.Copy(&buf, r)
out := buf.String()
assert.Contains(t, out, `"version": "1.0"`)
assert.Contains(t, out, `"analytics"`)
assert.Equal(t, content, out)
}

func TestRunManifestOnlyNotFound(t *testing.T) {
Expand All @@ -664,3 +664,26 @@ func TestRunManifestOnlyNotFound(t *testing.T) {
out := buf.String()
assert.Equal(t, "No appkit.plugins.json manifest found in this template.\n", out)
}

func TestRunManifestOnlyUsesTemplatePathEnvVar(t *testing.T) {
dir := t.TempDir()
manifestPath := filepath.Join(dir, manifest.ManifestFileName)
content := `{"version":"1.0","scaffolding":{"command":"databricks apps init"}}`
require.NoError(t, os.WriteFile(manifestPath, []byte(content), 0o644))

old := os.Stdout
r, w, err := os.Pipe()
require.NoError(t, err)
os.Stdout = w

ctx := env.Set(t.Context(), templatePathEnvVar, dir)
err = runManifestOnly(ctx, "", "", "")
w.Close()
os.Stdout = old
require.NoError(t, err)

var buf bytes.Buffer
_, _ = io.Copy(&buf, r)
out := buf.String()
assert.Equal(t, content, out)
}
13 changes: 6 additions & 7 deletions cmd/apps/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package apps

import (
"context"
"encoding/json"
"errors"
"fmt"
"os"
Expand Down Expand Up @@ -55,15 +54,15 @@ func runManifestOnly(ctx context.Context, templatePath, branch, version string)
}

if manifest.HasManifest(templateDir) {
m, err := manifest.Load(templateDir)
path := filepath.Join(templateDir, manifest.ManifestFileName)
data, err := os.ReadFile(path)
if err != nil {
return fmt.Errorf("load manifest: %w", err)
return fmt.Errorf("read manifest: %w", err)
}
enc, err := json.MarshalIndent(m, "", " ")
_, err = os.Stdout.Write(data)
if err != nil {
return fmt.Errorf("encode manifest: %w", err)
return fmt.Errorf("write manifest: %w", err)
}
fmt.Fprintln(os.Stdout, string(enc))
return nil
}

Expand All @@ -83,7 +82,7 @@ func newManifestCmd() *cobra.Command {
Short: "Print template manifest with available plugins and required resources",
Hidden: true,
Long: `Resolves a template (default AppKit repo or --template URL), locates appkit.plugins.json,
and prints its contents to stdout. No workspace authentication is required.
and prints its raw contents to stdout. No workspace authentication is required.

Use the same --template, --branch, and --version flags as "databricks apps init" to target
a specific template. Without --template, uses the default AppKit template (main branch).
Expand Down
Loading