@@ -4,8 +4,16 @@ import {
44 Profiles ,
55 resolveConfigFilePath ,
66} from "@databricks/databricks-sdk" ;
7- import { stat , unlink } from "fs/promises" ;
8- import { QuickPickItem , QuickPickItemKind , window } from "vscode" ;
7+ import { copyFile , stat , unlink } from "fs/promises" ;
8+ import path from "path" ;
9+ import {
10+ commands ,
11+ QuickPickItem ,
12+ QuickPickItemKind ,
13+ Uri ,
14+ window ,
15+ workspace ,
16+ } from "vscode" ;
917import { CliWrapper } from "../cli/CliWrapper" ;
1018import { MultiStepInput } from "../ui/wizard" ;
1119
@@ -37,23 +45,49 @@ export async function selectProfile(
3745 if ( ! ( e instanceof ConfigFileError ) ) {
3846 throw e ;
3947 }
40- const path = resolveConfigFilePath ( ) ;
48+ const confPath = resolveConfigFilePath ( ) ;
4149 let stats ;
4250 try {
43- stats = await stat ( path ) ;
51+ stats = await stat ( confPath ) ;
4452 } catch ( e ) {
4553 /*file doesn't exist*/
4654 }
4755 if ( stats ?. isFile ( ) ) {
4856 const option = await window . showErrorMessage (
49- e . message ,
50- "Overwrite" ,
51- "Cancel"
57+ `Can't parse config file` ,
58+ {
59+ detail : e . message ,
60+ } ,
61+ "Open Config File" ,
62+ "Backup and Overwrite Config File"
5263 ) ;
53- if ( option === "Cancel" ) {
64+ if ( option === undefined ) {
65+ return ;
66+ }
67+ if ( option === "Open Config File" ) {
68+ await commands . executeCommand (
69+ "databricks.connection.openDatabricksConfigFile"
70+ ) ;
5471 return ;
5572 }
56- await unlink ( path ) ;
73+ const backupPath = path . join (
74+ path . dirname ( confPath ) ,
75+ `${ path . basename ( confPath ) } .${ Date . now ( ) } .bak`
76+ ) ;
77+ await copyFile ( confPath , backupPath ) ;
78+
79+ const openBackup = await window . showErrorMessage (
80+ `Config file backed up at "${ backupPath } "` ,
81+ "Open Backup File" ,
82+ "Continue Without Opening"
83+ ) ;
84+ if ( openBackup === "Open Backup File" ) {
85+ const doc = await workspace . openTextDocument (
86+ Uri . file ( backupPath )
87+ ) ;
88+ await window . showTextDocument ( doc ) ;
89+ }
90+ await unlink ( confPath ) ;
5791 }
5892 }
5993
0 commit comments