feat(struct_tags): add support for custom transform option
This commit is contained in:
parent
4217211912
commit
e2f3096a5f
2 changed files with 16 additions and 2 deletions
|
|
@ -1,6 +1,14 @@
|
||||||
---@type gopher.Config
|
---@type gopher.Config
|
||||||
local config = {}
|
local config = {}
|
||||||
|
|
||||||
|
---@alias gopher.ConfigGoTagTransform
|
||||||
|
---| "snakecase" "GopherUser" -> "gopher_user"
|
||||||
|
---| "camelcase" "GopherUser" -> "gopherUser"
|
||||||
|
---| "lispcase" "GopherUser" -> "gopher-user"
|
||||||
|
---| "pascalcase" "GopherUser" -> "GopherUser"
|
||||||
|
---| "titlecase" "GopherUser" -> "Gopher User"
|
||||||
|
---| "keep" keeps the original field name
|
||||||
|
|
||||||
---@class gopher.Config
|
---@class gopher.Config
|
||||||
local default_config = {
|
local default_config = {
|
||||||
---@class gopher.ConfigCommand
|
---@class gopher.ConfigCommand
|
||||||
|
|
@ -20,6 +28,11 @@ local default_config = {
|
||||||
---@type string|nil
|
---@type string|nil
|
||||||
template_dir = nil,
|
template_dir = nil,
|
||||||
},
|
},
|
||||||
|
---@class gopher.ConfigGoTag
|
||||||
|
gotag = {
|
||||||
|
---@type gopher.ConfigGoTagTransform
|
||||||
|
transform = "snakecase",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
---@type gopher.Config
|
---@type gopher.Config
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
local ts_utils = require "gopher._utils.ts"
|
local ts_utils = require "gopher._utils.ts"
|
||||||
local r = require "gopher._utils.runner"
|
local r = require "gopher._utils.runner"
|
||||||
local c = require("gopher.config").commands
|
local c = require "gopher.config"
|
||||||
local struct_tags = {}
|
local struct_tags = {}
|
||||||
|
|
||||||
local function modify(...)
|
local function modify(...)
|
||||||
|
|
@ -12,6 +12,7 @@ local function modify(...)
|
||||||
|
|
||||||
-- stylua: ignore
|
-- stylua: ignore
|
||||||
local cmd_args = {
|
local cmd_args = {
|
||||||
|
"-transform", c.gotag.transform,
|
||||||
"-format", "json",
|
"-format", "json",
|
||||||
"-file", fpath,
|
"-file", fpath,
|
||||||
"-w"
|
"-w"
|
||||||
|
|
@ -38,7 +39,7 @@ local function modify(...)
|
||||||
table.insert(cmd_args, "json")
|
table.insert(cmd_args, "json")
|
||||||
end
|
end
|
||||||
|
|
||||||
local output = r.sync(c.gomodifytags, {
|
local output = r.sync(c.commands.gomodifytags, {
|
||||||
args = cmd_args,
|
args = cmd_args,
|
||||||
on_exit = function(data, status)
|
on_exit = function(data, status)
|
||||||
if not status == 0 then
|
if not status == 0 then
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue