From 56a90dbb0bdc7db59857301427825e5a7fc2900f Mon Sep 17 00:00:00 2001 From: dwenegar Date: Thu, 18 Jul 2019 08:31:43 +0900 Subject: Add `--dir` option to the `new_version` command (#1014) --- src/luarocks/cmd/new_version.lua | 17 ++++++++++++++--- src/luarocks/util.lua | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/luarocks/cmd/new_version.lua b/src/luarocks/cmd/new_version.lua index f1181d40..19b5fa1e 100644 --- a/src/luarocks/cmd/new_version.lua +++ b/src/luarocks/cmd/new_version.lua @@ -8,10 +8,11 @@ local download = require("luarocks.download") local fetch = require("luarocks.fetch") local persist = require("luarocks.persist") local fs = require("luarocks.fs") +local dir = require("luarocks.dir") local type_rockspec = require("luarocks.type.rockspec") new_version.help_summary = "Auto-write a rockspec for a new version of a rock." -new_version.help_arguments = "[--tag=] [|] [] []" +new_version.help_arguments = "[--tag=] [--dir=] [|] [] []" new_version.help = [[ This is a utility function that writes a new rockspec, updating data from a previous one. @@ -34,7 +35,9 @@ the new MD5 checksum. If a tag is given, it replaces the one from the old rockspec. If there is an old tag but no new one passed, it is guessed in the same way URL is. -WARNING: it writes the new rockspec to the current directory, +If a directory is not given, it defaults to the current directory. + +WARNING: it writes the new rockspec to the given directory, overwriting the file if it already exists. ]] @@ -158,6 +161,11 @@ function new_version.command(flags, input, version, url) version = flags.tag:gsub("^v", "") end + local out_dir + if flags.dir then + out_dir = dir.normalize(flags.dir) + end + if version then new_ver, new_rev = version:match("(.*)%-(%d+)$") new_rev = tonumber(new_rev) @@ -183,7 +191,10 @@ function new_version.command(flags, input, version, url) end local out_filename = out_name.."-"..new_rockver.."-"..new_rev..".rockspec" - + if out_dir then + out_filename = dir.path(out_dir, out_filename) + fs.make_dir(out_dir) + end persist.save_from_table(out_filename, out_rs, type_rockspec.order) util.printout("Wrote "..out_filename) diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index 1f7bd484..57cefc61 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua @@ -97,6 +97,7 @@ local supported_flags = { ["deps-mode"] = "", ["detailed"] = "\"\"", ["dev"] = true, + ["dir"] = "", ["force"] = true, ["force-fast"] = true, ["from"] = "", -- cgit v1.2.3-55-g6feb