diff options
author | Peter Melnichenko <mpeterval@gmail.com> | 2016-05-07 14:21:36 +0300 |
---|---|---|
committer | Peter Melnichenko <mpeterval@gmail.com> | 2016-05-22 19:50:40 +0300 |
commit | 470ca122e9120caac00cae44b472965a8828afb4 (patch) | |
tree | 47559d00fdc01c6d88491757cd90af136557712d /src | |
parent | 319f8f619c9457c8ba426d8bbe0b1d2d74c02e5d (diff) | |
download | luarocks-470ca122e9120caac00cae44b472965a8828afb4.tar.gz luarocks-470ca122e9120caac00cae44b472965a8828afb4.tar.bz2 luarocks-470ca122e9120caac00cae44b472965a8828afb4.zip |
Expose tools.command_at function
Diffstat (limited to 'src')
-rw-r--r-- | src/luarocks/fs/unix/tools.lua | 12 | ||||
-rw-r--r-- | src/luarocks/fs/win32/tools.lua | 12 |
2 files changed, 16 insertions, 8 deletions
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua index 904dd0aa..807f8057 100644 --- a/src/luarocks/fs/unix/tools.lua +++ b/src/luarocks/fs/unix/tools.lua | |||
@@ -9,7 +9,11 @@ local cfg = require("luarocks.cfg") | |||
9 | 9 | ||
10 | local vars = cfg.variables | 10 | local vars = cfg.variables |
11 | 11 | ||
12 | local function command_at(directory, cmd) | 12 | --- Adds prefix to command to make it run from a directory. |
13 | -- @param directory string: Path to a directory. | ||
14 | -- @param cmd string: A command-line string. | ||
15 | -- @return string: The command-line with prefix. | ||
16 | function tools.command_at(directory, cmd) | ||
13 | return "cd " .. fs.Q(fs.absolute_name(directory)) .. " && " .. cmd | 17 | return "cd " .. fs.Q(fs.absolute_name(directory)) .. " && " .. cmd |
14 | end | 18 | end |
15 | 19 | ||
@@ -21,7 +25,7 @@ end | |||
21 | function tools.execute_string(cmd) | 25 | function tools.execute_string(cmd) |
22 | local current = fs.current_dir() | 26 | local current = fs.current_dir() |
23 | if not current then return false end | 27 | if not current then return false end |
24 | local code, err = os.execute(command_at(current, cmd)) | 28 | local code, err = os.execute(fs.command_at(current, cmd)) |
25 | if code == 0 or code == true then | 29 | if code == 0 or code == true then |
26 | return true | 30 | return true |
27 | else | 31 | else |
@@ -114,7 +118,7 @@ end | |||
114 | -- @param at string: directory to list | 118 | -- @param at string: directory to list |
115 | -- @return nil | 119 | -- @return nil |
116 | function tools.dir_iterator(at) | 120 | function tools.dir_iterator(at) |
117 | local pipe = io.popen(command_at(at, vars.LS)) | 121 | local pipe = io.popen(fs.command_at(at, vars.LS)) |
118 | for file in pipe:lines() do | 122 | for file in pipe:lines() do |
119 | if file ~= "." and file ~= ".." then | 123 | if file ~= "." and file ~= ".." then |
120 | coroutine.yield(file) | 124 | coroutine.yield(file) |
@@ -137,7 +141,7 @@ function tools.find(at) | |||
137 | return {} | 141 | return {} |
138 | end | 142 | end |
139 | local result = {} | 143 | local result = {} |
140 | local pipe = io.popen(command_at(at, fs.quiet_stderr(vars.FIND.." *"))) | 144 | local pipe = io.popen(fs.command_at(at, fs.quiet_stderr(vars.FIND.." *"))) |
141 | for file in pipe:lines() do | 145 | for file in pipe:lines() do |
142 | table.insert(result, file) | 146 | table.insert(result, file) |
143 | end | 147 | end |
diff --git a/src/luarocks/fs/win32/tools.lua b/src/luarocks/fs/win32/tools.lua index aa405e14..f2d62f32 100644 --- a/src/luarocks/fs/win32/tools.lua +++ b/src/luarocks/fs/win32/tools.lua | |||
@@ -11,7 +11,11 @@ local cfg = require("luarocks.cfg") | |||
11 | 11 | ||
12 | local vars = cfg.variables | 12 | local vars = cfg.variables |
13 | 13 | ||
14 | local function command_at(directory, cmd) | 14 | --- Adds prefix to command to make it run from a directory. |
15 | -- @param directory string: Path to a directory. | ||
16 | -- @param cmd string: A command-line string. | ||
17 | -- @return string: The command-line with prefix. | ||
18 | function tools.command_at(directory, cmd) | ||
15 | local drive = directory:match("^([A-Za-z]:)") | 19 | local drive = directory:match("^([A-Za-z]:)") |
16 | cmd = "cd " .. fs.Q(directory) .. " & " .. cmd | 20 | cmd = "cd " .. fs.Q(directory) .. " & " .. cmd |
17 | if drive then | 21 | if drive then |
@@ -28,7 +32,7 @@ end | |||
28 | function tools.execute_string(cmd) | 32 | function tools.execute_string(cmd) |
29 | local current = fs.current_dir() | 33 | local current = fs.current_dir() |
30 | if not current then return false end | 34 | if not current then return false end |
31 | cmd = command_at(current, cmd) | 35 | cmd = fs.command_at(current, cmd) |
32 | local code = os.execute(cmd) | 36 | local code = os.execute(cmd) |
33 | if code == 0 or code == true then | 37 | if code == 0 or code == true then |
34 | return true | 38 | return true |
@@ -115,7 +119,7 @@ end | |||
115 | -- @param at string: directory to list | 119 | -- @param at string: directory to list |
116 | -- @return nil | 120 | -- @return nil |
117 | function tools.dir_iterator(at) | 121 | function tools.dir_iterator(at) |
118 | local pipe = io.popen(command_at(at, fs.Q(vars.LS))) | 122 | local pipe = io.popen(fs.command_at(at, fs.Q(vars.LS))) |
119 | for file in pipe:lines() do | 123 | for file in pipe:lines() do |
120 | if file ~= "." and file ~= ".." then | 124 | if file ~= "." and file ~= ".." then |
121 | coroutine.yield(file) | 125 | coroutine.yield(file) |
@@ -138,7 +142,7 @@ function tools.find(at) | |||
138 | return {} | 142 | return {} |
139 | end | 143 | end |
140 | local result = {} | 144 | local result = {} |
141 | local pipe = io.popen(command_at(at, fs.quiet_stderr(fs.Q(vars.FIND)))) | 145 | local pipe = io.popen(fs.command_at(at, fs.quiet_stderr(fs.Q(vars.FIND)))) |
142 | for file in pipe:lines() do | 146 | for file in pipe:lines() do |
143 | -- Windows find is a bit different | 147 | -- Windows find is a bit different |
144 | local first_two = file:sub(1,2) | 148 | local first_two = file:sub(1,2) |