diff options
Diffstat (limited to 'src/luarocks/command_line.lua')
| -rw-r--r-- | src/luarocks/command_line.lua | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua index f2afc16a..d501d121 100644 --- a/src/luarocks/command_line.lua +++ b/src/luarocks/command_line.lua | |||
| @@ -21,6 +21,18 @@ local function die(message) | |||
| 21 | os.exit(1) | 21 | os.exit(1) |
| 22 | end | 22 | end |
| 23 | 23 | ||
| 24 | local function is_writable(tree) | ||
| 25 | if type(tree) == "string" then | ||
| 26 | return fs.make_dir(tree) and fs.is_writable(tree) | ||
| 27 | else | ||
| 28 | writable = true | ||
| 29 | for k, v in pairs(tree) do | ||
| 30 | writable = writable and fs.make_dir(v) and fs.is_writable(v) | ||
| 31 | end | ||
| 32 | return writable | ||
| 33 | end | ||
| 34 | end | ||
| 35 | |||
| 24 | --- Main command-line processor. | 36 | --- Main command-line processor. |
| 25 | -- Parses input arguments and calls the appropriate driver function | 37 | -- Parses input arguments and calls the appropriate driver function |
| 26 | -- to execute the action requested on the command-line, forwarding | 38 | -- to execute the action requested on the command-line, forwarding |
| @@ -45,6 +57,7 @@ function run_command(...) | |||
| 45 | end | 57 | end |
| 46 | local nonflags = { util.parse_flags(unpack(args)) } | 58 | local nonflags = { util.parse_flags(unpack(args)) } |
| 47 | local flags = table.remove(nonflags, 1) | 59 | local flags = table.remove(nonflags, 1) |
| 60 | cfg.flags = flags | ||
| 48 | 61 | ||
| 49 | if flags["to"] then | 62 | if flags["to"] then |
| 50 | if flags["to"] == true then | 63 | if flags["to"] == true then |
| @@ -60,24 +73,28 @@ function run_command(...) | |||
| 60 | local trees = cfg.rocks_trees | 73 | local trees = cfg.rocks_trees |
| 61 | for i = #trees, 1, -1 do | 74 | for i = #trees, 1, -1 do |
| 62 | local tree = trees[i] | 75 | local tree = trees[i] |
| 63 | if fs.make_dir(tree) and fs.is_writable(tree) then | 76 | if is_writable(tree) then |
| 64 | cfg.root_dir = tree | 77 | cfg.root_dir = tree |
| 65 | cfg.rocks_dir = path.rocks_dir(tree) | 78 | cfg.rocks_dir = path.rocks_dir(tree) |
| 66 | cfg.deploy_bin_dir = rawget(cfg, "deploy_bin_dir") or path.deploy_bin_dir(tree) | 79 | cfg.deploy_bin_dir = path.deploy_bin_dir(tree) |
| 67 | cfg.deploy_lua_dir = rawget(cfg, "deploy_lua_dir") or path.deploy_lua_dir(tree) | 80 | cfg.deploy_lua_dir = path.deploy_lua_dir(tree) |
| 68 | cfg.deploy_lib_dir = rawget(cfg, "deploy_lib_dir") or path.deploy_lib_dir(tree) | 81 | cfg.deploy_lib_dir = path.deploy_lib_dir(tree) |
| 69 | break | 82 | break |
| 70 | end | 83 | end |
| 71 | end | 84 | end |
| 72 | end | 85 | end |
| 73 | 86 | ||
| 74 | cfg.root_dir = cfg.root_dir:gsub("/+$", "") | 87 | if type(cfg.root_dir) == "string" then |
| 88 | cfg.root_dir = cfg.root_dir:gsub("/+$", "") | ||
| 89 | else | ||
| 90 | cfg.root_dir.root = cfg.root_dir.root:gsub("/+$", "") | ||
| 91 | end | ||
| 75 | cfg.rocks_dir = cfg.rocks_dir:gsub("/+$", "") | 92 | cfg.rocks_dir = cfg.rocks_dir:gsub("/+$", "") |
| 76 | cfg.deploy_bin_dir = cfg.deploy_bin_dir:gsub("/+$", "") | 93 | cfg.deploy_bin_dir = cfg.deploy_bin_dir:gsub("/+$", "") |
| 77 | cfg.deploy_lua_dir = cfg.deploy_lua_dir:gsub("/+$", "") | 94 | cfg.deploy_lua_dir = cfg.deploy_lua_dir:gsub("/+$", "") |
| 78 | cfg.deploy_lib_dir = cfg.deploy_lib_dir:gsub("/+$", "") | 95 | cfg.deploy_lib_dir = cfg.deploy_lib_dir:gsub("/+$", "") |
| 79 | 96 | ||
| 80 | cfg.variables.ROCKS_TREE = cfg.root_dir | 97 | cfg.variables.ROCKS_TREE = cfg.rocks_dir |
| 81 | cfg.variables.SCRIPTS_DIR = cfg.deploy_bin_dir | 98 | cfg.variables.SCRIPTS_DIR = cfg.deploy_bin_dir |
| 82 | 99 | ||
| 83 | if flags["from"] then | 100 | if flags["from"] then |
