Skip to content

Commit 73689f7

Browse files
committed
Minor fixes
- Update diffmatchpatch to Google's version - Allow --help and -h - Add source mapping to patchspecs - Add _G.arg to environment
1 parent 0702650 commit 73689f7

15 files changed

+555
-693
lines changed

bsrocks/bin/bsrocks.lua

+14-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ local commands = { }
22

33
local function addCommand(command)
44
commands[command.name] = command
5+
if command.alias then
6+
for _, v in ipairs(command.alias) do
7+
commands[v] = command
8+
end
9+
end
510
end
611

712
local utils = require "bsrocks.lib.utils"
@@ -86,10 +91,17 @@ addCommand({
8691
printColoured(" " .. command.help, colours.lightGrey)
8792
end
8893
end
89-
end,
94+
end
9095
})
9196

9297
-- Default to printing help messages
93-
local foundCommand = getCommand(... or "help")
98+
local cmd = ...
99+
if not cmd or cmd == "-h" or cmd == "--help" then
100+
cmd = "help"
101+
elseif select(2, ...) == "-h" or select(2, ...) == "--help" then
102+
return getCommand("help").execute(cmd)
103+
end
104+
105+
local foundCommand = getCommand(cmd)
94106
local args = {...}
95107
return foundCommand.execute(select(2, unpack(args)))

bsrocks/commands/admin/addpatchspec.lua

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
local download = require "bsrocks.downloaders"
21
local fileWrapper = require "bsrocks.lib.files"
32
local manifest = require "bsrocks.rocks.manifest"
43
local patchDirectory = require "bsrocks.lib.settings".patchDirectory

bsrocks/commands/admin/addrockspec.lua

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
local download = require "bsrocks.downloaders"
21
local fileWrapper = require "bsrocks.lib.files"
32
local manifest = require "bsrocks.rocks.manifest"
43
local patchDirectory = require "bsrocks.lib.settings".patchDirectory

bsrocks/commands/admin/apply.lua

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ local function execute(...)
2020
end
2121
end
2222

23-
local changed = false
23+
local hasChanged = false
2424
for name, data in pairs(patched) do
2525
local original = fs.combine(patchDirectory, "rocks-original/" .. name)
2626
local patch = fs.combine(patchDirectory, "rocks/" .. name)
2727
local changed = fs.combine(patchDirectory, "rocks-changes/" .. name)
2828

2929
if force or not fs.isDir(changed) then
30-
changed = true
30+
hasChanged = true
3131
log("Applying " .. name)
3232

3333
fileWrapper.assertExists(original, "original sources for " .. name, 0)
@@ -46,7 +46,7 @@ local function execute(...)
4646
end
4747
end
4848

49-
if not changed then
49+
if not hasChanged then
5050
error("No packages to patch", 0)
5151
end
5252
end

bsrocks/commands/admin/fetch.lua

+8-8
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ local function execute(...)
2323
end
2424
end
2525

26-
local changed = false
27-
for name, patchspec in pairs(patched) do
26+
local hasChanged = false
27+
for name, patchS in pairs(patched) do
2828
local dir = fs.combine(patchDirectory, "rocks-original/" .. name)
2929
if force or not fs.isDir(dir) then
30-
changed = true
30+
hasChanged = true
3131
log("Fetching " .. name)
3232

3333
fs.delete(dir)
3434

35-
local version = patchspec.version
36-
if not patchspec.version then
35+
local version = patchS.version
36+
if not patchS.version then
3737
error("Patchspec" .. name .. " has no version", 0)
3838
end
3939

@@ -42,12 +42,12 @@ local function execute(...)
4242
error("Cannot find '" .. name .. "'", 0)
4343
end
4444

45-
local rock = rockspec.fetchRockspec(manifest.server, name, patchspec.version)
45+
local rock = rockspec.fetchRockspec(manifest.server, name, patchS.version)
4646

4747
local files = rockspec.extractFiles(rock)
4848
if #files == 0 then error("No files for " .. name .. "-" .. version, 0) end
4949

50-
local downloaded = download(rock.source, files)
50+
local downloaded = download(patchspec.extractSource(rock, patchS), files)
5151

5252
if not downloaded then error("Cannot find downloader for " .. rock.source.url, 0) end
5353

@@ -59,7 +59,7 @@ local function execute(...)
5959
end
6060
end
6161

62-
if not changed then
62+
if not hasChanged then
6363
error("No packages to fetch", 0)
6464
end
6565

bsrocks/commands/desc.lua

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local dependencies = require "bsrocks.rocks.dependencies"
2+
local download = require "bsrocks.downloaders"
23
local install = require "bsrocks.rocks.install"
34
local match = require "bsrocks.lib.diffmatchpatch".match_main
45
local printColoured = require "bsrocks.lib.utils".printColoured
@@ -55,6 +56,11 @@ local function execute(name)
5556
end
5657
end
5758

59+
if not download(spec.source, nil) then
60+
printColoured("Incompatible: No downloader", colours.red)
61+
printColoured("for " .. spec.source.url, colours.lightGrey)
62+
end
63+
5864
if spec.dependencies and #spec.dependencies > 0 then
5965
printColoured("Dependencies", colours.orange)
6066
local len = 0

bsrocks/commands/exec.lua

+5-2
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ return {
1616
description = description,
1717
execute = function(file, ...)
1818
if not file then error("Expected file", 0) end
19+
file = shell.resolve(file)
1920

20-
local loaded, msg = loadfile(shell.resolve(file))
21+
local loaded, msg = loadfile(file)
2122
if not loaded then error(msg, 0) end
2223

23-
setfenv(loaded, env()._G)
24+
local thisEnv = env()._G
25+
thisEnv.arg = {[0] = fil, ... }
26+
setfenv(loaded, thisEnv)
2427

2528
local args = {...}
2629
xpcall(

bsrocks/commands/repl.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ local env = require "bsrocks.env"
22
local serialize = require "bsrocks.lib.dump"
33
local parse = require "bsrocks.lib.parse"
44

5-
local function execute()
5+
local function execute(...)
66
local running = true
77
local thisEnv = env()._G
88

@@ -13,6 +13,7 @@ local function execute()
1313

1414
-- We need to pass through a secondary function to prevent tail calls
1515
thisEnv._noTail = function(...) return ... end
16+
thisEnv.arg = { [0] = "repl", ... }
1617

1718
-- As per @demhydraz's suggestion. Because the prompt uses Out[n] as well
1819
local output = {}

bsrocks/downloaders/init.lua

+7-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ local downloaders = {
1414
if not repo then return end
1515
end
1616

17+
if not files then
18+
return true
19+
end
20+
1721
print("Downloading " .. repo .. "@" .. branch)
1822
return tree('https://raw.github.com/'..repo..'/'..branch..'/', files)
1923
end,
@@ -22,10 +26,9 @@ local downloaders = {
2226

2327
return function(source, files)
2428
for _, downloader in ipairs(downloaders) do
25-
local files = downloader(source, files)
26-
if files then
27-
print()
28-
return files
29+
local result = downloader(source, files)
30+
if result then
31+
return result
2932
end
3033
end
3134

bsrocks/downloaders/tree.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ local function tree(prefix, files)
5656
end
5757

5858
parallel.waitForAll(unpack(callbacks))
59+
print()
5960
if errored then
60-
error("Cannot download " .. repo .. "@" .. branch)
61+
error("Cannot download " .. prefix)
6162
end
6263

6364
return result

bsrocks/env/init.lua

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1+
local function addWithMeta(src, dest)
2+
for k, v in pairs(src) do
3+
if dest[k] == nil then
4+
dest[k] = v
5+
end
6+
end
7+
8+
local meta = getmetatable(src)
9+
if type(meta) == "table" and type(meta.__index) == "table" then
10+
return addWithMeta(meta.__index, dest)
11+
end
12+
end
13+
114
return function(options)
2-
local globals = _G
315
options = options or {}
416

517
local nImplemented = function(name)
@@ -36,15 +48,7 @@ return function(options)
3648
end
3749

3850
-- Copy functions across
39-
for k,v in pairs(globals) do
40-
if not _G[k] then
41-
_G[k] = v
42-
end
43-
end
44-
45-
-- FIXME:
46-
_G.shell = shell
47-
_G.multishell = multishell
51+
addWithMeta(getfenv(), _G)
4852

4953
function _G.load(func, chunk)
5054
local cache = {}

bsrocks/env/package.lua

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ return function(env)
1616
preload = {},
1717
path = path,
1818
config = "/\n;\n?\n!\n-",
19+
cpath = "",
1920
}
2021
-- Set as a global
2122
_G.package = package

0 commit comments

Comments
 (0)