aboutsummaryrefslogtreecommitdiff
path: root/src/luarocks/command_line.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/luarocks/command_line.lua')
-rw-r--r--src/luarocks/command_line.lua72
1 files changed, 34 insertions, 38 deletions
diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua
index d501d121..71ded87d 100644
--- a/src/luarocks/command_line.lua
+++ b/src/luarocks/command_line.lua
@@ -33,6 +33,14 @@ local function is_writable(tree)
33 end 33 end
34end 34end
35 35
36local function use_tree(tree)
37 cfg.root_dir = tree
38 cfg.rocks_dir = path.rocks_dir(tree)
39 cfg.deploy_bin_dir = path.deploy_bin_dir(tree)
40 cfg.deploy_lua_dir = path.deploy_lua_dir(tree)
41 cfg.deploy_lib_dir = path.deploy_lib_dir(tree)
42end
43
36--- Main command-line processor. 44--- Main command-line processor.
37-- Parses input arguments and calls the appropriate driver function 45-- Parses input arguments and calls the appropriate driver function
38-- to execute the action requested on the command-line, forwarding 46-- to execute the action requested on the command-line, forwarding
@@ -58,30 +66,39 @@ function run_command(...)
58 local nonflags = { util.parse_flags(unpack(args)) } 66 local nonflags = { util.parse_flags(unpack(args)) }
59 local flags = table.remove(nonflags, 1) 67 local flags = table.remove(nonflags, 1)
60 cfg.flags = flags 68 cfg.flags = flags
69
70 local command
71
72 if flags["version"] then
73 print(program_name.." "..cfg.program_version)
74 print(program_description)
75 print()
76 os.exit(0)
77 elseif flags["help"] or #nonflags == 0 then
78 command = "help"
79 args = nonflags
80 else
81 command = nonflags[1]
82 for i, arg in ipairs(args) do
83 if arg == command then
84 table.remove(args, i)
85 break
86 end
87 end
88 end
89 command = command:gsub("-", "_")
61 90
62 if flags["to"] then 91 if flags["to"] then
63 if flags["to"] == true then 92 if flags["to"] == true then
64 die("Argument error: use --to=<path>") 93 die("Argument error: use --to=<path>")
65 end 94 end
66 local root_dir = fs.absolute_name(flags["to"]) 95 local root_dir = fs.absolute_name(flags["to"])
67 cfg.root_dir = root_dir 96 use_tree(root_dir)
68 cfg.rocks_dir = path.rocks_dir(root_dir) 97 elseif flags["local"] then
69 cfg.deploy_bin_dir = path.deploy_bin_dir(root_dir) 98 use_tree(cfg.home_tree)
70 cfg.deploy_lua_dir = path.deploy_lua_dir(root_dir)
71 cfg.deploy_lib_dir = path.deploy_lib_dir(root_dir)
72 else 99 else
73 local trees = cfg.rocks_trees 100 local trees = cfg.rocks_trees
74 for i = #trees, 1, -1 do 101 use_tree(trees[#trees])
75 local tree = trees[i]
76 if is_writable(tree) then
77 cfg.root_dir = tree
78 cfg.rocks_dir = path.rocks_dir(tree)
79 cfg.deploy_bin_dir = path.deploy_bin_dir(tree)
80 cfg.deploy_lua_dir = path.deploy_lua_dir(tree)
81 cfg.deploy_lib_dir = path.deploy_lib_dir(tree)
82 break
83 end
84 end
85 end 102 end
86 103
87 if type(cfg.root_dir) == "string" then 104 if type(cfg.root_dir) == "string" then
@@ -111,34 +128,13 @@ function run_command(...)
111 end 128 end
112 cfg.rocks_servers = { flags["only-from"] } 129 cfg.rocks_servers = { flags["only-from"] }
113 end 130 end
114 131
115 local command
116
117 if flags["version"] then
118 print(program_name.." "..cfg.program_version)
119 print(program_description)
120 print()
121 os.exit(0)
122 elseif flags["help"] or #nonflags == 0 then
123 command = "help"
124 args = nonflags
125 else
126 command = nonflags[1]
127 for i, arg in ipairs(args) do
128 if arg == command then
129 table.remove(args, i)
130 break
131 end
132 end
133 end
134
135 if command ~= "help" then 132 if command ~= "help" then
136 for k, v in pairs(cmdline_vars) do 133 for k, v in pairs(cmdline_vars) do
137 cfg.variables[k] = v 134 cfg.variables[k] = v
138 end 135 end
139 end 136 end
140 137
141 command = command:gsub("-", "_")
142 if commands[command] then 138 if commands[command] then
143 local xp, ok, err = xpcall(function() return commands[command].run(unpack(args)) end, function(err) 139 local xp, ok, err = xpcall(function() return commands[command].run(unpack(args)) end, function(err)
144 die(debug.traceback("LuaRocks "..cfg.program_version 140 die(debug.traceback("LuaRocks "..cfg.program_version