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