2121local config = require (" devcontainer-cli.config" )
2222local folder_utils = require (" devcontainer-cli.folder_utils" )
2323local terminal = require (" devcontainer-cli.terminal" )
24+ local log = require (" devcontainer-cli.log" )
2425
2526local M = {}
2627
9697local function _devcontainer_command (action )
9798 local devcontainer_root = folder_utils .get_root (config .toplevel )
9899 if devcontainer_root == nil then
99- vim . notify ( " Unable to find devcontainer directory..." , vim . log . levels . ERROR )
100+ log . error ( " unable to find devcontainer directory..." )
100101 return nil
101102 end
102103
@@ -159,9 +160,7 @@ function M.bringup()
159160 },
160161 function (input )
161162 if (input == " q" or input == " Q" ) then
162- vim .notify (
163- " \n User cancelled bringing up devcontainer"
164- )
163+ log .info (" \n User cancelled bringing up devcontainer" )
165164 else
166165 terminal .spawn (command )
167166 end
@@ -184,7 +183,7 @@ function M._exec_cmd(cmd, direction, size)
184183 end
185184
186185 command = command .. " " .. config .shell .. " -c '" .. cmd .. " '"
187- vim . notify (command )
186+ log . info (command )
188187 terminal .spawn (command , direction , size )
189188end
190189
195194--- @param size (number | nil ) size of the window to create
196195function M .exec (cmd , direction , size )
197196 if terminal .is_open () then
198- vim . notify ( " There is already a devcontainer process running." , vim . log . levels . WARN )
197+ log . warn ( " there is already a devcontainer process running." )
199198 return
200199 end
201200
@@ -206,7 +205,7 @@ function M.exec(cmd, direction, size)
206205 if input ~= nil then
207206 M ._exec_cmd (input , direction , size )
208207 else
209- vim . notify ( " No command received, ignoring." , vim . log . levels . WARN )
208+ log . warn ( " no command received, ignoring." )
210209 end
211210 end
212211 )
@@ -242,7 +241,7 @@ function M.create_connect_cmd()
242241 elseif vim .fn .executable (" Terminal.app" ) == 1 then
243242 connect_command = { " Terminal.app" }
244243 else
245- vim . notify ( " No supported terminal emulator found." , vim . log . levels . ERROR )
244+ log . error ( " no supported terminal emulator found." )
246245 end
247246
248247 table.insert (connect_command , dev_command )
@@ -259,4 +258,28 @@ function M.create_connect_cmd()
259258 return true
260259end
261260
261+ -- issues command to down devcontainer
262+ function M .down ()
263+ local workspace = folder_utils .get_root (config .toplevel )
264+ if workspace == nil then
265+ log .error (" Couldn't determine project root" )
266+ return
267+ end
268+
269+ local tag = workspace .. " /.devcontainer/devcontainer.json"
270+ local command = " docker ps -q -a --filter label=devcontainer.config_file=" .. tag
271+ log .debug (" Attempting to get pid of devcontainer using command: " .. command )
272+ local result = vim .fn .systemlist (command )
273+
274+ if # result == 0 then
275+ log .warn (" Couldn't find devcontainer to kill" )
276+ return
277+ end
278+
279+ local pid = result [1 ]
280+ command = " docker kill " .. pid
281+ log .info (" Killing docker container with pid: " .. pid )
282+ terminal .spawn (command )
283+ end
284+
262285return M
0 commit comments