From 54c147c88537a682e5f926ea391c14ae31c80f82 Mon Sep 17 00:00:00 2001 From: Daniil Rozanov Date: Thu, 2 May 2024 00:15:28 +0300 Subject: feat: new commands and some refactoring --- lua/cmake/commands.lua | 109 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 79 insertions(+), 30 deletions(-) (limited to 'lua/cmake/commands.lua') diff --git a/lua/cmake/commands.lua b/lua/cmake/commands.lua index c2f6e75..d763958 100644 --- a/lua/cmake/commands.lua +++ b/lua/cmake/commands.lua @@ -1,39 +1,88 @@ +local commandline = require("cmake.commandline") +local actions = require("cmake.actions") + local M = {} local cmd = vim.api.nvim_create_user_command -M.register_commands = function() - cmd("CMakeGenerate", function() - require("cmake.actions").generate() - end, { desc = "Generate with last configuration" }) - - cmd("CMakeGenerateSelect", function() - require("cmake.actions").generate_select() - end, { desc = "Select configuration and generate" }) - - cmd("CMakeBuild", function() - require("cmake.actions").build() - end, { desc = "Build with last build option" }) +local prefix = "CMake" - cmd("CMakeBuildSelect", function() - require("cmake.actions").build_select() - end, { desc = "Select build option and build" }) +local commands = { + ["Generate"] = { + command = actions.generate, + parse = true, + default_opts = { fresh = false }, + cmd_opts = { + desc = "Generate with last configuration", + nargs = "*", + complete = commandline.cmake_generate_complete, + }, + }, + ["GenerateExplain"] = { + command = actions.generate_explain, + parse = true, + default_opts = { fresh = false }, + cmd_opts = { + desc = "Explain current generate command", + nargs = "*", + complete = commandline.cmake_generate_complete, + }, + }, + ["GenerateSelect"] = { + command = actions.generate_select, + cmd_opts = { desc = "Select generate configuration" }, + }, + ["Build"] = { + command = actions.build, + parse = true, + cmd_opts = { + desc = "Build with last configuration", + nargs = "*", + complete = commandline.cmake_build_complete, + }, + }, + ["BuildExplain"] = { + command = actions.build_explain, + parse = true, + cmd_opts = { + desc = "Explain current build command", + nargs = "*", + complete = commandline.cmake_build_complete, + }, + }, + ["BuildSelect"] = { + command = actions.build_select, + cmd_opts = { desc = "Select build configuration" }, + }, + -- ["Install"] = {}, + ["Run"] = { + command = actions.run_target, + cmd_opts = { desc = "Run current executable target", nargs = "*" }, + }, + ["RunSelect"] = { + command = actions.run_target_select, + cmd_opts = { desc = "Select executable target" }, + }, + ["Toggle"] = { + command = actions.toggle, + cmd_opts = { desc = "Toggle cmake terminal" }, + }, + ["EditVariants"] = { + command = actions.edit_variants, + cmd_opts = { desc = "Edit variants" }, + }, +} - cmd("CMakeRun", function() - require("cmake.actions").run_tagret() - end, { desc = "Select build option and build" }) - - cmd("CMakeRunSelect", function() - require("cmake.actions").run_tagret_select() - end, { desc = "Select build option and build" }) - - cmd("CMakeToggle", function() - require("cmake.actions").toggle() - end, { desc = "Toggle terminal with cmake command" }) - - cmd("CMakeEditVariants", function() - require("cmake.actions").edit_variants() - end, { desc = "Edit variants" }) +M.register_commands = function() + for k, v in pairs(commands) do + cmd(prefix .. k, function(opts) + local action_opts = v.default_opts or {} + if v.parse then + action_opts = vim.tbl_deep_extend("keep", commandline.parse(opts.args) or {}, action_opts) + end + v.command(action_opts) + end, v.cmd_opts) + end end return M -- cgit v1.2.3