Skip to content

Commit

Permalink
Several bug fixes
Browse files Browse the repository at this point in the history
- Fix global creation
- Re-apply fix with gmatch on wildcard in diffmatchpatch
- Fix issue with names arguments to make and apply commands
- Add completions provider
  • Loading branch information
SquidDev committed Feb 26, 2016
1 parent 31522bc commit 6ed606b
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 9 deletions.
30 changes: 30 additions & 0 deletions bsrocks/bin/completions.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
local function completeMultipleChoice(text, options)
local results = {}
for n=1, #options do
local option = options[n]
if #option > #text and option:sub(1, #text) == text then
local result = option:sub(#text + 1)
table.insert(results, result .. " ")
end
end
return results
end

local options = {
"dest", "dump-settings", "exec", "install", "list",
"remove", "repl", "search",

"add-patchspec", "add-rockspec", "apply-patches", "fetch", "make-patches"
}

local function completeBsRocks(shell, index, text, previous)
if index == 1 then
return completeMultipleChoice(text, options)
elseif nIndex == 2 then
if previous[2] == "exec" then
return fs.complete(sText, shell.dir(), true, false )
end
end
end

shell.setCompletionFunction(shell.resolve(...), completeBsRocks)
3 changes: 2 additions & 1 deletion bsrocks/commands/admin/apply.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ local function execute(...)
patched = patchspec.getAll()
else
force = true
patched = {}
for _, name in pairs({...}) do
name = name:lower()
local file = fs.combine(patchDirectory, name .. ".patchspec")
local file = fs.combine(patchDirectory, "rocks/" .. name .. ".patchspec")
if not fs.exists(file) then error("No such patchspec " .. name, 0) end

patched[name] = serialize.unserialize(fileWrapper.read(file))
Expand Down
3 changes: 2 additions & 1 deletion bsrocks/commands/admin/make.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ local function execute(...)
patched = patchspec.getAll()
else
force = true
patched = {}
for _, name in pairs({...}) do
name = name:lower()
local file = fs.combine(patchDirectory, name .. ".patchspec")
local file = fs.combine(patchDirectory, "rocks/" .. name .. ".patchspec")
if not fs.exists(file) then error("No such patchspec " .. name, 0) end

patched[name] = serialize.unserialize(fileWrapper.read(file))
Expand Down
1 change: 0 additions & 1 deletion bsrocks/commands/desc.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
local dependencies = require "bsrocks.rocks.dependencies"
local download = require "bsrocks.downloaders"
local install = require "bsrocks.rocks.install"
local match = require "bsrocks.lib.diffmatchpatch".match_main
local patchspec = require "bsrocks.rocks.patchspec"
local printColoured = require "bsrocks.lib.utils".printColoured
local rockspec = require "bsrocks.rocks.rockspec"
Expand Down
1 change: 1 addition & 0 deletions bsrocks/env/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ return function(options)
_VERSION = _VERSION
}
_G._G = _G
_G._ENV = _ENV

local env = {
_G = _G,
Expand Down
9 changes: 5 additions & 4 deletions bsrocks/lib/diffmatchpatch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ local Patch_Margin = 4
-- The number of bits in an int.
local Match_MaxBits = 32

function settings(new)
local function settings(new)
if new then
Diff_Timeout = new.Diff_Timeout or Diff_Timeout
Diff_EditCost = new.Diff_EditCost or Diff_EditCost
Expand Down Expand Up @@ -149,6 +149,7 @@ end
local
_diff_compute,
_diff_bisect,
_diff_bisectSplit,
_diff_halfMatchI,
_diff_halfMatch,
_diff_cleanupSemanticScore,
Expand Down Expand Up @@ -1320,7 +1321,7 @@ local _match_bitap, _match_alphabet
--]]
function match_main(text, pattern, loc)
-- Check for null inputs.
if text == nil or pattern == nil or loc == nil then
if text == nil or pattern == nil then
error('Null inputs. (match_main)')
end

Expand All @@ -1331,7 +1332,7 @@ function match_main(text, pattern, loc)
-- Nothing to match.
return -1
end
loc = max(1, min(loc, #text))
loc = max(1, min(loc or 0, #text))
if strsub(text, loc, loc + #pattern - 1) == pattern then
-- Perfect match at the perfect spot! (Includes case of null pattern)
return loc
Expand Down Expand Up @@ -1756,7 +1757,7 @@ function patch_fromText(textline)
return patches
end
local text = {}
for line in gmatch(textline, '([^\n]*)') do
for line in gmatch(textline .. "\n", '([^\n]*)\n') do
text[#text + 1] = line
end
local textPointer = 1
Expand Down
4 changes: 2 additions & 2 deletions bsrocks/rocks/dependencies.lua
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ end
-- @param input string: A list of constraints in string format.
-- @return table or nil: A table representing the same constraints,
-- or nil if the input string is invalid.
function parseConstraints(input)
local function parseConstraints(input)
assert(type(input) == "string")

local constraints, constraint, oinput = {}, nil, input
Expand Down Expand Up @@ -234,7 +234,7 @@ end
-- @param constraints table: An array of constraints in table format.
-- @return boolean: True if version satisfies all constraints,
-- false otherwise.
function matchConstraints(version, constraints)
local function matchConstraints(version, constraints)
assert(type(version) == "table")
assert(type(constraints) == "table")

Expand Down

0 comments on commit 6ed606b

Please sign in to comment.