Skip to content

Commit 7196f7b

Browse files
Use bricks cli for profile configuration (#78)
1 parent 0eb9e6c commit 7196f7b

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

packages/databricks-vscode/src/cli/CliCommands.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ export class CliCommands {
77

88
constructor(private cli: CliWrapper) {}
99

10-
testBricksCommand(context: ExtensionContext) {
10+
testBricksCommand() {
1111
return () => {
12-
const {command, args} = this.cli.getTestBricksCommand(context);
12+
const {command, args} = this.cli.getTestBricksCommand();
1313
const cmd = spawn(command, args);
1414

1515
cmd.stdout.on("data", (data) => {

packages/databricks-vscode/src/cli/CliWrapper.test.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import * as assert from "assert";
22
import {Uri} from "vscode";
33
import {SyncDestination} from "../configuration/SyncDestination";
4+
import {ExtensionContext} from "vscode";
45

56
import {CliWrapper} from "./CliWrapper";
7+
import {mock, spy} from "ts-mockito";
68

79
describe(__filename, () => {
810
it("should create sync command", () => {
9-
const cli = new CliWrapper();
11+
const cli = new CliWrapper({
12+
asAbsolutePath(path: string) {
13+
return path;
14+
},
15+
} as any);
1016
const mapper = new SyncDestination(
1117
Uri.from({
1218
scheme: "dbws",
@@ -29,7 +35,11 @@ describe(__filename, () => {
2935
});
3036

3137
it("should create full sync command", () => {
32-
const cli = new CliWrapper();
38+
const cli = new CliWrapper({
39+
asAbsolutePath(path: string) {
40+
return path;
41+
},
42+
} as any);
3343
const mapper = new SyncDestination(
3444
Uri.from({
3545
scheme: "dbws",
@@ -52,7 +62,11 @@ describe(__filename, () => {
5262
});
5363

5464
it("should create an 'add profile' command", () => {
55-
const cli = new CliWrapper();
65+
const cli = new CliWrapper({
66+
asAbsolutePath(path: string) {
67+
return path;
68+
},
69+
} as any);
5670

5771
const {command, args} = cli.getAddProfileCommand(
5872
"DEFAULT",
@@ -61,7 +75,7 @@ describe(__filename, () => {
6175

6276
assert.equal(
6377
[command, ...args].join(" "),
64-
"databricks configure --profile DEFAULT --host https://databricks.com/ --token"
78+
"./bin/bricks configure --no-interactive --profile DEFAULT --host https://databricks.com/ --token"
6579
);
6680
});
6781
});

packages/databricks-vscode/src/cli/CliWrapper.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ export interface Command {
1414
* of the bricks CLI
1515
*/
1616
export class CliWrapper {
17-
constructor() {}
17+
constructor(private context: ExtensionContext) {}
1818

19-
getTestBricksCommand(context: ExtensionContext): Command {
19+
getTestBricksCommand(): Command {
2020
return {
21-
command: context.asAbsolutePath("./bin/bricks"),
21+
command: this.context.asAbsolutePath("./bin/bricks"),
2222
args: [],
2323
};
2424
}
@@ -53,9 +53,10 @@ export class CliWrapper {
5353

5454
getAddProfileCommand(profile: string, host: URL): Command {
5555
return {
56-
command: "databricks",
56+
command: this.context.asAbsolutePath("./bin/bricks"),
5757
args: [
5858
"configure",
59+
"--no-interactive",
5960
"--profile",
6061
profile,
6162
"--host",
@@ -76,7 +77,7 @@ export class CliWrapper {
7677
stdio: ["pipe", 0, 0],
7778
});
7879

79-
child.stdin!.write(token);
80+
child.stdin!.write(`${token}\n`);
8081
child.stdin!.end();
8182

8283
child.on("error", reject);

packages/databricks-vscode/src/extension.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ import {CodeSynchronizer} from "./sync/CodeSynchronizer";
1515
import {BricksTaskProvider} from "./cli/BricksTasks";
1616

1717
export function activate(context: ExtensionContext) {
18-
let cli = new CliWrapper();
19-
18+
let cli = new CliWrapper(context);
2019
// Configuration group
2120
let connectionManager = new ConnectionManager(cli);
2221
connectionManager.login(false);
@@ -173,7 +172,7 @@ export function activate(context: ExtensionContext) {
173172
),
174173
commands.registerCommand(
175174
"databricks.cli.testBricksCli",
176-
cliCommands.testBricksCommand(context),
175+
cliCommands.testBricksCommand(),
177176
cliCommands
178177
)
179178
);

0 commit comments

Comments
 (0)