From 294902970d1937c790764d20ef9abf35d58b67f7 Mon Sep 17 00:00:00 2001 From: Smirnov Oleksandr Date: Fri, 7 Oct 2022 16:41:40 +0300 Subject: [PATCH] feat: move all lua api into `api` module --- lua/gopher/api.lua | 26 ++++++++++++++++++++++++++ lua/gopher/init.lua | 20 +++----------------- plugin/gopher.vim | 24 ++++++++++++------------ 3 files changed, 41 insertions(+), 29 deletions(-) create mode 100644 lua/gopher/api.lua diff --git a/lua/gopher/api.lua b/lua/gopher/api.lua new file mode 100644 index 0000000..f708c52 --- /dev/null +++ b/lua/gopher/api.lua @@ -0,0 +1,26 @@ +local API = {} +local tags = require "gopher.struct_tags" +local tests = require "gopher.gotests" +local cmd = require "gopher._utils.commands" + +API.install_deps = require "gopher.installer" +API.tags_add = tags.add +API.tags_rm = tags.remove +API.impl = require "gopher.impl" +API.iferr = require "gopher.iferr" +API.comment = require "gopher.comment" +API.test_add = tests.func_test +API.test_exported = tests.all_exported_tests +API.tests_all = tests.all_tests + +API.get = function(...) + cmd("get", ...) +end +API.mod = function(...) + cmd("mod", ...) +end +API.generate = function(...) + cmd("generate", ...) +end + +return API diff --git a/lua/gopher/init.lua b/lua/gopher/init.lua index 39f5ca9..46b649e 100644 --- a/lua/gopher/init.lua +++ b/lua/gopher/init.lua @@ -1,19 +1,5 @@ -local tags = require "gopher.struct_tags" -local gotests = require "gopher.gotests" -local gopher = {} +local GOPHER = {} -gopher.install_deps = require "gopher.installer" -gopher.tags_add = tags.add -gopher.tags_rm = tags.remove -gopher.mod = require "gopher.gomod" -gopher.get = require "gopher.goget" -gopher.impl = require "gopher.impl" -gopher.generate = require "gopher.gogenerate" -gopher.iferr = require "gopher.iferr" -gopher.comment = require "gopher.comment" -gopher.test_add = gotests.func_test -gopher.test_exported = gotests.all_exported_tests -gopher.tests_all = gotests.all_tests -gopher.setup = require("gopher.config").setup +GOPHER.setup = require("gopher.config").setup -return gopher +return GOPHER diff --git a/plugin/gopher.vim b/plugin/gopher.vim index 089c330..a00addb 100644 --- a/plugin/gopher.vim +++ b/plugin/gopher.vim @@ -1,12 +1,12 @@ -command! -nargs=* GoTagAdd :lua require"gopher".tags_add() -command! -nargs=* GoTagRm :lua require"gopher".tags_rm() -command! -nargs=* GoTestAdd :lua require"gopher".test_add() -command! -nargs=* GoTestsAll :lua require"gopher".tests_all() -command! -nargs=* GoTestsExp :lua require"gopher".test_exported() -command! -nargs=* GoMod :lua require"gopher".mod() -command! -nargs=* GoGet :lua require"gopher".get() -command! -nargs=* GoImpl :lua require"gopher".impl() -command! -nargs=* GoGenerate :lua require"gopher".generate() -command! GoCmt :lua require"gopher".comment() -command! GoIfErr :lua require"gopher".iferr() -command! GoInstallDeps :lua require"gopher".install_deps() +command! -nargs=* GoTagAdd :lua require"gopher.api".tags_add() +command! -nargs=* GoTagRm :lua require"gopher.api".tags_rm() +command! -nargs=* GoTestAdd :lua require"gopher.api".test_add() +command! -nargs=* GoTestsAll :lua require"gopher.api".tests_all() +command! -nargs=* GoTestsExp :lua require"gopher.api".test_exported() +command! -nargs=* GoMod :lua require"gopher.api".mod() +command! -nargs=* GoGet :lua require"gopher.api".get() +command! -nargs=* GoImpl :lua require"gopher.api".impl() +command! -nargs=* GoGenerate :lua require"gopher.api".generate() +command! GoCmt :lua require"gopher.api".comment() +command! GoIfErr :lua require"gopher.api".iferr() +command! GoInstallDeps :lua require"gopher.api".install_deps()