From 470ca122e9120caac00cae44b472965a8828afb4 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Sat, 7 May 2016 14:21:36 +0300 Subject: Expose tools.command_at function --- src/luarocks/fs/unix/tools.lua | 12 ++++++++---- src/luarocks/fs/win32/tools.lua | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) (limited to 'src') 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") local vars = cfg.variables -local function command_at(directory, cmd) +--- Adds prefix to command to make it run from a directory. +-- @param directory string: Path to a directory. +-- @param cmd string: A command-line string. +-- @return string: The command-line with prefix. +function tools.command_at(directory, cmd) return "cd " .. fs.Q(fs.absolute_name(directory)) .. " && " .. cmd end @@ -21,7 +25,7 @@ end function tools.execute_string(cmd) local current = fs.current_dir() if not current then return false end - local code, err = os.execute(command_at(current, cmd)) + local code, err = os.execute(fs.command_at(current, cmd)) if code == 0 or code == true then return true else @@ -114,7 +118,7 @@ end -- @param at string: directory to list -- @return nil function tools.dir_iterator(at) - local pipe = io.popen(command_at(at, vars.LS)) + local pipe = io.popen(fs.command_at(at, vars.LS)) for file in pipe:lines() do if file ~= "." and file ~= ".." then coroutine.yield(file) @@ -137,7 +141,7 @@ function tools.find(at) return {} end local result = {} - local pipe = io.popen(command_at(at, fs.quiet_stderr(vars.FIND.." *"))) + local pipe = io.popen(fs.command_at(at, fs.quiet_stderr(vars.FIND.." *"))) for file in pipe:lines() do table.insert(result, file) 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") local vars = cfg.variables -local function command_at(directory, cmd) +--- Adds prefix to command to make it run from a directory. +-- @param directory string: Path to a directory. +-- @param cmd string: A command-line string. +-- @return string: The command-line with prefix. +function tools.command_at(directory, cmd) local drive = directory:match("^([A-Za-z]:)") cmd = "cd " .. fs.Q(directory) .. " & " .. cmd if drive then @@ -28,7 +32,7 @@ end function tools.execute_string(cmd) local current = fs.current_dir() if not current then return false end - cmd = command_at(current, cmd) + cmd = fs.command_at(current, cmd) local code = os.execute(cmd) if code == 0 or code == true then return true @@ -115,7 +119,7 @@ end -- @param at string: directory to list -- @return nil function tools.dir_iterator(at) - local pipe = io.popen(command_at(at, fs.Q(vars.LS))) + local pipe = io.popen(fs.command_at(at, fs.Q(vars.LS))) for file in pipe:lines() do if file ~= "." and file ~= ".." then coroutine.yield(file) @@ -138,7 +142,7 @@ function tools.find(at) return {} end local result = {} - local pipe = io.popen(command_at(at, fs.quiet_stderr(fs.Q(vars.FIND)))) + local pipe = io.popen(fs.command_at(at, fs.quiet_stderr(fs.Q(vars.FIND)))) for file in pipe:lines() do -- Windows find is a bit different local first_two = file:sub(1,2) -- cgit v1.2.3-55-g6feb