From 598856047fe584a740329523447ff3f679fbc459 Mon Sep 17 00:00:00 2001 From: Erich L Foster Date: Sat, 27 Apr 2024 14:20:01 +0200 Subject: [PATCH] Add simple health check --- README.md | 12 ++++++------ doc/devcontainer_cli.txt | 6 +++--- lua/devcontainer_cli/health.lua | 29 +++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 lua/devcontainer_cli/health.lua diff --git a/README.md b/README.md index 0158460..b37adb5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# Devcontainer CLI (Nvim Plugin) +# Devcontainer CLI (NVIM Plugin) -Develop your next Repo in a Devcontainer using Nvim thanks to the +Develop your next Repo in a Devcontainer using *nvim* thanks to the [Devconatiner CLI](https://github.com/devcontainers/cli) and this plugin ![](doc/gifs/nvim_devcontainer_cli-description.gif) @@ -54,7 +54,7 @@ But, what is happening under the hood? A very nice devcontainer feature that can do this is [apt package](https://github.com/rocker-org/devcontainer-features/tree/main/src/apt-packages). 3. The last step is connecting inside the container via `devcontainer exec` - ([here](https://github.com/erichlf/nvim-devcontainer-cli/blob/main/bin/connect_to_devcontainer.sh)). + ([here](https://github.com/erichlf/devcontainer-cli.nvim/blob/main/bin/connect_to_devcontainer.sh)). The main thing this plugin does is bringup your devcontainer and execute commands via a convenient interface. It attempts to stay out of your way and @@ -63,7 +63,7 @@ allows you to do things as you wish, but gives you the tools to do that easily. **Inspiration:** This plugin has been inspired by the work previously done by -[arnaupv](https://github.com/arnaupv/nvim-devcontainer-cli), +[arnaupv](https://github.com/arnaupv/devcontainer-cli.nvim), [esensar](https://github.com/esensar/nvim-dev-container) and by [jamestthompson3](https://github.com/jamestthompson3/nvim-remote-containers). The main difference between this version and arnaupv is that it tries to not @@ -80,7 +80,7 @@ make assumptions about how you work. ```lua { - "erichlf/nvim-devcontainer-cli", + "erichlf/devcontainer-cli.nvim", opts = { -- whather to verify that the final devcontainer should be run interactive = false, @@ -178,7 +178,7 @@ make test 1. [x] Capability to create and run a devcontainer using the [Devconatiner CLI](https://github.com/devcontainers/cli). 2. [x] Capability to attach in a running devcontainer. 3. [x] The floating window created during the devcontainer Up process (:DevcontainerUp) is closed when the process finishes successfully. -4. [x] [Give the possibility of defining custom dotfiles when setting up the devcontainer](https://github.com/erichlf/nvim-devcontainer-cli/issues/1) +4. [x] [Give the possibility of defining custom dotfiles when setting up the devcontainer](https://github.com/erichlf/devcontainer-cli.nvim/issues/1) 5. [ ] Add unit tests using plenary.busted lua module. 6. [ ] The logs printed in the floating window when preparing the Devcontainer are saved and easy to access. 7. [ ] Convert bash scripts in lua code. diff --git a/doc/devcontainer_cli.txt b/doc/devcontainer_cli.txt index a04f201..cfcb71f 100644 --- a/doc/devcontainer_cli.txt +++ b/doc/devcontainer_cli.txt @@ -1,14 +1,14 @@ ================================================================================ - *nvim-devcontainer-cli* + *devcontainer-cli.nvim* -nvim-devcontainer-cli is a nvim plugin which intends to use the devcontainer-cli +devcontainer-cli.nvim is a nvim plugin which intends to use the devcontainer-cli developed by microsoft for creating your own local development environments when developing docker containers. Development is in progress, but the plugin can already be used. To find out more: -https://github.com/erichlf/nvim-devcontainer-cli +https://github.com/erichlf/devcontainer-cli.nvim :h DevcontainerUp diff --git a/lua/devcontainer_cli/health.lua b/lua/devcontainer_cli/health.lua new file mode 100644 index 0000000..91a482b --- /dev/null +++ b/lua/devcontainer_cli/health.lua @@ -0,0 +1,29 @@ +local remote_nvim = require("remote-nvim") +local utils = require("remote-nvim.utils") +local M = {} + +local function verify_binary(binary_name) + local succ, _ = pcall(utils.find_binary, binary_name) + if not succ then + vim.health.error(("`%s` executable not found."):format(binary_name)) + else + vim.health.ok(("`%s` executable found."):format(binary_name)) + end +end +-- TODO: create a test that checks that a devcontainer can be brought up, +-- this needs to be done after creating the ability to stop a container +-- TODO: create a test that checks that a command can be executed within the +-- running container + +function M.check() + vim.health.start("devcontainer_cli") + local required_binaries = { + "docker", + "devcontainer-cli", + } + for _, bin_name in ipairs(required_binaries) do + verify_binary(bin_name) + end +end + +return M