1
1
import * as vscode from 'vscode' ;
2
2
import { ContainerlabTreeDataProvider } from './containerlabTreeDataProvider' ;
3
+ import { promisify } from 'util' ;
4
+ import { exec } from 'child_process' ;
3
5
import {
4
6
deploy ,
5
7
deployCleanup ,
@@ -21,9 +23,32 @@ import {
21
23
} from './commands/index' ;
22
24
23
25
export let outputChannel : vscode . OutputChannel ;
26
+ const execAsync = promisify ( exec ) ;
24
27
25
- export function activate ( context : vscode . ExtensionContext ) {
28
+ export async function activate ( context : vscode . ExtensionContext ) {
26
29
outputChannel = vscode . window . createOutputChannel ( "Containerlab" ) ;
30
+ context . subscriptions . push ( outputChannel ) ;
31
+
32
+ // Check if containerlab is installed
33
+ let versionOutput : string ;
34
+ try {
35
+ const { stdout } = await execAsync ( 'sudo containerlab version' ) ;
36
+ versionOutput = stdout ;
37
+ } catch ( err ) {
38
+ // Show error message with button to open installation guide
39
+ const installAction = 'Open Installation Guide' ;
40
+ const selection = await vscode . window . showErrorMessage (
41
+ 'containerlab not detected. Please install it first.' ,
42
+ installAction
43
+ ) ;
44
+
45
+ if ( selection === installAction ) {
46
+ vscode . env . openExternal ( vscode . Uri . parse ( 'https://containerlab.dev/install/' ) ) ;
47
+ }
48
+ versionOutput = '' ;
49
+ }
50
+
51
+
27
52
const provider = new ContainerlabTreeDataProvider ( ) ;
28
53
vscode . window . registerTreeDataProvider ( 'containerlabExplorer' , provider ) ;
29
54
@@ -62,7 +87,6 @@ export function activate(context: vscode.ExtensionContext) {
62
87
} , refreshInterval ) ;
63
88
context . subscriptions . push ( { dispose : ( ) => clearInterval ( intervalId ) } ) ;
64
89
65
- vscode . window . showInformationMessage ( 'Containerlab Extension is now active!' ) ;
66
90
}
67
91
68
92
export function deactivate ( ) { }
0 commit comments