-
Notifications
You must be signed in to change notification settings - Fork 102
New hidden install-pipelines-cli
command that creates pipelines
symlink to databricks
#3009
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 22 commits
60260b7
6750e38
359a77d
d12a848
e3c41fc
ca3d09b
d168e96
c282769
e771366
9fac6c7
14b7d31
be032fa
6429b3a
2bf67ef
9bf008f
8576254
523c76d
ce1c01a
cc6454b
8e020dc
12b1e64
2d8da98
1da3ff0
be778d6
f9dc119
fb62458
9156ad5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
=== install dlt | ||
>>> errcode [CLI] install-dlt -o json | ||
dlt successfully installed in directory "[BUILD_DIR]" | ||
|
||
>>> [BUILD_DIR]/dlt | ||
DLT command verified | ||
|
||
=== dlt already installed | ||
>>> errcode [CLI] install-dlt | ||
dlt already installed in directory "[BUILD_DIR]" | ||
|
||
=== dlt file exists, should not overwrite | ||
>>> errcode [CLI] install-dlt -d tmpdir -o json | ||
cannot install dlt CLI: "tmpdir/dlt" already exists | ||
Error: installation failed | ||
|
||
Exit code: 1 | ||
|
||
=== Executable not called as databricks | ||
>>> errcode ./notdatabricks install-dlt -o json | ||
dlt successfully installed in directory "[TEST_TMP_DIR]" | ||
|
||
>>> [TEST_TMP_DIR]/dlt | ||
DLT command verified |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
title "install dlt" | ||
dlt=$(trace errcode $CLI install-dlt -o json | jq -r .symlink_path) | ||
alyssa-db marked this conversation as resolved.
Show resolved
Hide resolved
alyssa-db marked this conversation as resolved.
Show resolved
Hide resolved
|
||
trace $dlt | head -n1 | grep -q "DLT CLI" && echo "DLT command verified" || echo "DLT command failed" | ||
alyssa-db marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
title "dlt already installed" | ||
trace errcode $CLI install-dlt | ||
alyssa-db marked this conversation as resolved.
Show resolved
Hide resolved
|
||
rm -f "$(dirname $CLI)/dlt" | ||
|
||
title "dlt file exists, should not overwrite" | ||
mkdir -p tmpdir | ||
touch tmpdir/dlt | ||
trace errcode $CLI install-dlt -d tmpdir -o json | jq -r .symlink_path | ||
rm -rf tmpdir | ||
|
||
title "Executable not called as databricks" | ||
cp $CLI notdatabricks | ||
dlt=$(trace errcode ./notdatabricks install-dlt -o json | jq -r .symlink_path) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's also not clear here what's being asserted. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the case that the user has databricks aliased, want to make sure the install-dlt command still works. |
||
trace $dlt | head -n1 | grep -q "DLT CLI" && echo "DLT command verified" || echo "DLT command failed" | ||
rm -f notdatabricks | ||
rm -f dlt |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Fix path with reverse slashes in the output for Windows. | ||
[[Repls]] | ||
Old = '\\\\' | ||
New = '/' | ||
|
||
[[Repls]] | ||
Old = '\\' | ||
New = '/' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package dlt | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func New() *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() | ||
alyssa-db marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
alyssa-db marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package dlt | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/databricks/cli/cmd/root" | ||
"github.com/databricks/cli/libs/cmdio" | ||
"github.com/databricks/cli/libs/flags" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type installDLTResponse struct { | ||
SymlinkPath string `json:"symlink_path"` | ||
} | ||
|
||
func installDLTSymlink(directory string) (string, error) { | ||
path, err := os.Executable() | ||
if err != nil { | ||
return "", err | ||
} | ||
realPath, err := filepath.EvalSymlinks(path) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
dir := directory | ||
if dir == "" { | ||
dir = filepath.Dir(path) | ||
} | ||
dltPath := filepath.Join(dir, "dlt") | ||
|
||
_, err = os.Lstat(dltPath) | ||
if err != nil { | ||
if !errors.Is(err, os.ErrNotExist) { | ||
return "", err | ||
} | ||
err = os.Symlink(realPath, dltPath) | ||
if err != nil { | ||
return "", err | ||
} | ||
cmdio.LogString(context.Background(), fmt.Sprintf("dlt successfully installed in directory %q", dir)) | ||
return dltPath, nil | ||
} | ||
|
||
target, err := filepath.EvalSymlinks(dltPath) | ||
if err != nil { | ||
return "", err | ||
} | ||
if realPath == target { | ||
cmdio.LogString(context.Background(), fmt.Sprintf("dlt already installed in directory %q", dir)) | ||
return dltPath, nil | ||
} | ||
cmdio.LogString(context.Background(), fmt.Sprintf("cannot install dlt CLI: %q already exists", dltPath)) | ||
alyssa-db marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return "", errors.New("installation failed") | ||
} | ||
|
||
func InstallDLT() *cobra.Command { | ||
var directory string | ||
cmd := &cobra.Command{ | ||
Use: "install-dlt", | ||
Short: "Install DLT", | ||
Hidden: true, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
dltPath, err := installDLTSymlink(directory) | ||
if err != nil { | ||
return err | ||
} | ||
response := installDLTResponse{ | ||
SymlinkPath: dltPath, | ||
} | ||
switch root.OutputType(cmd) { | ||
case flags.OutputJSON: | ||
alyssa-db marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return cmdio.Render(cmd.Context(), response) | ||
default: | ||
return nil | ||
} | ||
}, | ||
} | ||
cmd.Flags().StringVarP(&directory, "directory", "d", "", "Directory in which to install dlt CLI (defaults to databricks CLI's directory)") | ||
return cmd | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,14 +3,30 @@ package main | |
import ( | ||
"context" | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
|
||
"github.com/databricks/cli/cmd" | ||
"github.com/databricks/cli/cmd/dlt" | ||
"github.com/databricks/cli/cmd/root" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// If invoked as 'dlt' (or 'dlt.exe' on Windows), returns DLT-specific commands, | ||
// otherwise returns the databricks CLI commands. This is used to allow the same | ||
// binary to be used for both DLT and databricks CLI commands. | ||
func getCommand(ctx context.Context) *cobra.Command { | ||
invokedAs := filepath.Base(os.Args[0]) | ||
alyssa-db marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if invokedAs == "dlt" || (runtime.GOOS == "windows" && invokedAs == "dlt.exe") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: you can replace it with |
||
return dlt.New() | ||
} | ||
return cmd.New(ctx) | ||
} | ||
|
||
func main() { | ||
ctx := context.Background() | ||
err := root.Execute(ctx, cmd.New(ctx)) | ||
command := getCommand(ctx) | ||
err := root.Execute(ctx, command) | ||
if err != nil { | ||
os.Exit(1) | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.