From bc3ce2fdf495761e50a4cef46a700b2bcc794fbc Mon Sep 17 00:00:00 2001 From: Oleksandr Smirnov Date: Mon, 8 Dec 2025 17:38:43 +0200 Subject: [PATCH] feat(json2go): support manual input --- plugin/gopher.lua | 5 +++-- spec/fixtures/json2go/manual_input.go | 2 ++ spec/fixtures/json2go/manual_output.go | 7 +++++++ spec/integration/json2go_test.lua | 6 ++++++ 4 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 spec/fixtures/json2go/manual_input.go create mode 100644 spec/fixtures/json2go/manual_output.go diff --git a/plugin/gopher.lua b/plugin/gopher.lua index 47658fb..5b071b0 100644 --- a/plugin/gopher.lua +++ b/plugin/gopher.lua @@ -72,8 +72,9 @@ end) -- :GoJson cmd("GoJson", function(opts) - require("gopher.json2go").json2go(opts.fargs[1]) -end, "?") + local inp = ((opts.args ~= "" and opts.args) or nil) + require("gopher.json2go").json2go(inp) +end, "*") -- :GoTest cmd("GoTestAdd", function() diff --git a/spec/fixtures/json2go/manual_input.go b/spec/fixtures/json2go/manual_input.go new file mode 100644 index 0000000..c9ecbf5 --- /dev/null +++ b/spec/fixtures/json2go/manual_input.go @@ -0,0 +1,2 @@ +package main + diff --git a/spec/fixtures/json2go/manual_output.go b/spec/fixtures/json2go/manual_output.go new file mode 100644 index 0000000..bd5ac1c --- /dev/null +++ b/spec/fixtures/json2go/manual_output.go @@ -0,0 +1,7 @@ +package main + +type AutoGenerated struct { + User struct { + Name string `json:"name"` + } `json:"user"` +} diff --git a/spec/integration/json2go_test.lua b/spec/integration/json2go_test.lua index 473d66e..83b39ba 100644 --- a/spec/integration/json2go_test.lua +++ b/spec/integration/json2go_test.lua @@ -14,6 +14,12 @@ json2go["should convert interativly"] = function() end json2go["should convert argument"] = function() + local rs = t.setup_test("json2go/manual", child, { 2, 0 }) + child.cmd [[GoJson {"user": {"name": "user-ovic"}}]] + child.cmd "write" + + t.eq(t.readfile(rs.tmp), rs.fixtures.output) + t.cleanup(rs) end return T