Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
60260b7
New hidden install-dlt command that creates symlink in same PATH as d…
alyssa-db Jun 6, 2025
6750e38
addressed code comments prior to testing
alyssa-db Jun 10, 2025
359a77d
added acceptance tests
alyssa-db Jun 10, 2025
d12a848
modified acceptance test PATH to add databricks and helper tools
alyssa-db Jun 10, 2025
e3c41fc
Merge branch 'databricks:main' into install-dlt-feat
alyssa-db Jun 10, 2025
ca3d09b
made dlt path be based on executable
alyssa-db Jun 11, 2025
d168e96
added acceptance test python script, refactored install-dlt
alyssa-db Jun 12, 2025
c282769
draft acceptance test and acceptance test DLT setup
alyssa-db Jun 12, 2025
e771366
acceptance test logic
alyssa-db Jun 12, 2025
9fac6c7
Merge remote-tracking branch 'upstream/main' into install-dlt-feat
alyssa-db Jun 12, 2025
14b7d31
windows path
alyssa-db Jun 12, 2025
be032fa
trying environment variable changes'
alyssa-db Jun 13, 2025
6429b3a
test symlink
alyssa-db Jun 13, 2025
2bf67ef
Merge branch 'main' into install-dlt-feat
alyssa-db Jun 13, 2025
9bf008f
dlt init checker
alyssa-db Jun 13, 2025
8576254
erroring checks
alyssa-db Jun 13, 2025
523c76d
added line for python packages
alyssa-db Jun 13, 2025
ce1c01a
Merge branch 'main' into install-dlt-feat
alyssa-db Jun 17, 2025
cc6454b
Added json path output and refactoring
alyssa-db Jun 17, 2025
8e020dc
checking windows
alyssa-db Jun 17, 2025
12b1e64
not clean paths windows
alyssa-db Jun 18, 2025
2d8da98
error order
alyssa-db Jun 18, 2025
1da3ff0
removed json, added relative path to tests
alyssa-db Jun 18, 2025
be778d6
modified invoke statement
alyssa-db Jun 18, 2025
f9dc119
Merge branch 'main' into install-dlt-feat
alyssa-db Jun 19, 2025
fb62458
renamed dlt to pipelines
alyssa-db Jun 19, 2025
9156ad5
renamed to install-pipelines-cli
alyssa-db Jun 19, 2025
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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ build: tidy

snapshot:
go build -o .databricks/databricks
go build -o .databricks/dlt

schema:
go run ./bundle/internal/schema ./bundle/internal/schema ./bundle/schema/jsonschema.json
Expand Down
12 changes: 12 additions & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ package cmd

import (
"context"
"fmt"
"os"
"path/filepath"
"strings"

"github.com/databricks/cli/cmd/account"
"github.com/databricks/cli/cmd/api"
"github.com/databricks/cli/cmd/auth"
"github.com/databricks/cli/cmd/bundle"
"github.com/databricks/cli/cmd/configure"
"github.com/databricks/cli/cmd/dlt"
"github.com/databricks/cli/cmd/fs"
"github.com/databricks/cli/cmd/labs"
"github.com/databricks/cli/cmd/root"
Expand All @@ -25,6 +29,13 @@ const (
)

func New(ctx context.Context) *cobra.Command {
fmt.Println(os.Args)
fmt.Println(os.Args[0])
invokedAs := filepath.Base(os.Args[0])
if invokedAs == "dlt" {
return dlt.NewRoot()
}

cli := root.New(ctx)

// Add account subcommand.
Expand Down Expand Up @@ -76,6 +87,7 @@ func New(ctx context.Context) *cobra.Command {
cli.AddCommand(sync.New())
cli.AddCommand(version.New())
cli.AddCommand(selftest.New())
cli.AddCommand(dlt.New())

return cli
}
98 changes: 98 additions & 0 deletions cmd/dlt/dlt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package dlt

import (
"errors"
"fmt"
"os"
"os/exec"
"path/filepath"

"github.com/spf13/cobra"
)

// InstallDLTSymlink creates a symlink named 'dlt' pointing to the real databricks binary.
func InstallDLTSymlink() error {
path, err := exec.LookPath("databricks")
if err != nil {
return errors.New("databricks CLI not found in PATH")
}
realPath, err := filepath.EvalSymlinks(path)
if err != nil {
return fmt.Errorf("failed to resolve symlink: %w", err)
}

dir := filepath.Dir(path)

// Check write permission by trying to create and remove a temp file
testFile := filepath.Join(dir, ".permtest")
f, err := os.Create(testFile)
if err != nil {
return fmt.Errorf("no write permission in %s: %w", dir, err)
}
f.Close()
_ = os.Remove(testFile)

dltPath := filepath.Join(dir, "dlt")

// Check if 'dlt' already exists
if fi, err := os.Lstat(dltPath); err == nil {
if fi.Mode()&os.ModeSymlink != 0 {
target, err := os.Readlink(dltPath)
if err == nil && target == realPath {
return errors.New("dlt already installed")
}
}
return fmt.Errorf("cannot create symlink: %q already exists", dltPath)
} else if !os.IsNotExist(err) {
// Some other error occurred while checking
return fmt.Errorf("failed to check if %q exists: %w", dltPath, err)
}

if err := os.Symlink(realPath, dltPath); err != nil {
return fmt.Errorf("failed to create symlink: %w", err)
}
return nil
}

func New() *cobra.Command {
return &cobra.Command{
Use: "install-dlt",
Short: "Install DLT",
Hidden: true,
RunE: func(cmd *cobra.Command, args []string) error {
err := InstallDLTSymlink()
if err != nil {
if err.Error() == "dlt already installed" {
fmt.Println(err.Error())
return nil
}
return err
}
return nil
},
}
}

func NewRoot() *cobra.Command {
cmd := &cobra.Command{
Use: "dlt",
Short: "DLT CLI",
Long: "DLT CLI (stub, to be filled in)",
Run: func(cmd *cobra.Command, args []string) {
_ = cmd.Help()
},
}

// Add 'init' stub command (same description as bundle init)
initCmd := &cobra.Command{
Use: "init",
Short: "Initialize a new DLT project in the current directory",
Long: "Initialize a new DLT project in the current directory. This is a stub for future implementation.",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("dlt init is not yet implemented. This will initialize a new DLT project in the future.")
},
}
cmd.AddCommand(initCmd)

return cmd
}
113 changes: 113 additions & 0 deletions cmd/dlt/dlt_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package dlt

import (
"os"
"os/exec"
"path/filepath"
"runtime"
"testing"

"github.com/stretchr/testify/assert"
)

// Add your imports here

// Add your tests here

type dltTestEnv struct {
tempDir string
binName string
symlinkName string
databricksPath string
}

func setupDLTTestEnv(t *testing.T) *dltTestEnv {
tempDir := t.TempDir()
binName := "databricks"
symlinkName := "dlt"
if runtime.GOOS == "windows" {
binName += ".bat"
symlinkName += ".bat"
}
databricksPath := filepath.Join(tempDir, binName)
f, err := os.Create(databricksPath)
assert.NoError(t, err)
f.Close()
err = os.Chmod(databricksPath, 0o755)
assert.NoError(t, err)

oldPath := os.Getenv("PATH")
os.Setenv("PATH", tempDir+string(os.PathListSeparator)+oldPath)
t.Cleanup(func() { os.Setenv("PATH", oldPath) })

return &dltTestEnv{
tempDir: tempDir,
binName: binName,
symlinkName: symlinkName,
databricksPath: databricksPath,
}
}

func TestInstallDLTSymlink(t *testing.T) {
env := setupDLTTestEnv(t)

err := InstallDLTSymlink()
assert.NoError(t, err)
dltSymlink := filepath.Join(env.tempDir, env.symlinkName)
_, err = os.Lstat(dltSymlink)
assert.NoError(t, err, "symlink was not created")
}

func TestDLTSymlinkRunsInit(t *testing.T) {
env := setupDLTTestEnv(t)

var err error
var script string
if os.PathSeparator == '\\' {
script = "@echo off\necho databricks called with: %*\n"
} else {
script = "#!/bin/sh\necho databricks called with: $@\n"
}

// Overwrite the dummy 'databricks' binary as a shell/batch script that prints args
err = os.WriteFile(env.databricksPath, []byte(script), 0o755)
assert.NoError(t, err)

// Create the symlink
err = InstallDLTSymlink()
assert.NoError(t, err)

// Run the symlinked binary with 'init' and check it executes without error
dltSymlink := filepath.Join(env.tempDir, env.symlinkName)
cmd := exec.Command(dltSymlink, "init")
cmd.Dir = env.tempDir
output, err := cmd.CombinedOutput()
assert.NoErrorf(t, err, "failed to run dlt init: output: %s", string(output))

// Check the output is as expected
assert.Contains(t, string(output), "databricks", "unexpected output: got %q, want substring containing %q", string(output), "databricks")
assert.Contains(t, string(output), "init", "unexpected output: got %q, want substring containing %q", string(output), "databricks")
}

func TestInstallDLTSymlink_AlreadyExists(t *testing.T) {
env := setupDLTTestEnv(t)
dltPath := filepath.Join(env.tempDir, env.symlinkName)
err := os.WriteFile(dltPath, []byte("not a symlink"), 0o644)
assert.NoError(t, err)
err = InstallDLTSymlink()
assert.Error(t, err)
assert.Contains(t, err.Error(), "already exists", "expected error about symlink already existing, got: %v", err)
}

func TestInstallDLTSymlink_AlreadyInstalled(t *testing.T) {
env := setupDLTTestEnv(t)
realPath, err := filepath.EvalSymlinks(env.databricksPath)
assert.NoError(t, err)
dltPath := filepath.Join(env.tempDir, env.symlinkName)
err = os.Symlink(realPath, dltPath)
assert.NoError(t, err)

err = InstallDLTSymlink()
assert.Error(t, err)
assert.EqualError(t, err, "dlt already installed")
}
Loading