From ccf92207e1092ae339b74454168acca79af72d0e Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 30 Aug 2019 11:02:58 -0300 Subject: cmd: add compatibility mode for pre-argparse external commands See #1070. --- spec/external_spec.lua | 33 +++++++++++++++++++++ spec/fixtures/legacyexternalcommand-0.1-1.rockspec | 17 +++++++++++ spec/fixtures/legacyexternalcommand.lua | 34 ++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 spec/external_spec.lua create mode 100644 spec/fixtures/legacyexternalcommand-0.1-1.rockspec create mode 100644 spec/fixtures/legacyexternalcommand.lua (limited to 'spec') diff --git a/spec/external_spec.lua b/spec/external_spec.lua new file mode 100644 index 00000000..4f1b8dce --- /dev/null +++ b/spec/external_spec.lua @@ -0,0 +1,33 @@ +local test_env = require("spec.util.test_env") +local run = test_env.run +local testing_paths = test_env.testing_paths + +test_env.setup_specs() + +describe("LuaRocks external commands #integration", function() + setup(function() + test_env.mock_server_init() + end) + + teardown(function() + test_env.mock_server_done() + end) + + it("installs a legacy external command", function() + local rockspec = testing_paths.fixtures_dir .. "/legacyexternalcommand-0.1-1.rockspec" + assert.is_truthy(run.luarocks_bool("build " .. rockspec)) + assert.is.truthy(run.luarocks("show legacyexternalcommand")) + local output = run.luarocks("legacyexternalcommand") + assert.match("Argument missing", output) + output = run.luarocks("legacyexternalcommand foo") + assert.match("ARG1\tfoo", output) + assert.match("ARG2\tnil", output) + output = run.luarocks("legacyexternalcommand foo bar") + assert.match("ARG1\tfoo", output) + assert.match("ARG2\tbar", output) + output = run.luarocks("legacyexternalcommand foo bar bla") + assert.match("ARG1\tfoo", output) + assert.match("ARG2\tbar", output) + end) +end) + diff --git a/spec/fixtures/legacyexternalcommand-0.1-1.rockspec b/spec/fixtures/legacyexternalcommand-0.1-1.rockspec new file mode 100644 index 00000000..47bcbb0c --- /dev/null +++ b/spec/fixtures/legacyexternalcommand-0.1-1.rockspec @@ -0,0 +1,17 @@ +package = "legacyexternalcommand" +version = "0.1-1" +source = { + url = "http://localhost:8080/file/legacyexternalcommand.lua" +} +description = { + summary = "an external command with legacy arg parsing", +} +dependencies = { + "lua >= 5.1" +} +build = { + type = "builtin", + modules = { + ["luarocks.cmd.external.legacyexternalcommand"] = "legacyexternalcommand.lua", + } +} diff --git a/spec/fixtures/legacyexternalcommand.lua b/spec/fixtures/legacyexternalcommand.lua new file mode 100644 index 00000000..af575372 --- /dev/null +++ b/spec/fixtures/legacyexternalcommand.lua @@ -0,0 +1,34 @@ + +--- Module implementing an external command with legacy arg parsing. +local legacyexternalcommand = {} + +local util = require("luarocks.util") + +legacyexternalcommand.help_summary = "generate legacyexternalcommand package files of a rock." +legacyexternalcommand.help_arguments = "arg1 [arg2]" +legacyexternalcommand.help = [[ +This addon generates legacyexternalcommand package files of a rock. +First argument is the name of a rock, the second argument is optional +and needed when legacyexternalcommand uses another name (usually prefixed by lua-). +Files are generated with the source content of the rock and more +especially the rockspec. So, the rock is downloaded and unpacked. +]] + +--- Driver function for the "legacyexternalcommand" command. +-- @param arg1 string: arg1. +-- @param arg2 string: arg2 (optional) +-- @return boolean: true if successful +function legacyexternalcommand.command(flags, arg1, arg2) + if type(arg1) ~= 'string' then + return nil, "Argument missing. "..util.see_help('legacyexternalcommand') + end + + for k,v in pairs(flags) do + print("FLAGS", k,v) + end + print("ARG1", tostring(arg1)) + print("ARG2", tostring(arg2)) + return true +end + +return legacyexternalcommand -- cgit v1.2.3-55-g6feb