2018-04-29 14:17:41 +00:00
|
|
|
local util = require "util"
|
|
|
|
local conf = util.conf
|
2018-04-29 14:40:57 +00:00
|
|
|
local query = util.query
|
2018-04-29 14:17:41 +00:00
|
|
|
|
|
|
|
rednet.open(conf.modem)
|
|
|
|
|
|
|
|
if conf.introspection then
|
|
|
|
conf.introspection = peripheral.call(conf.introspection, "getInventory")
|
|
|
|
end
|
|
|
|
|
|
|
|
local function split(str, sep)
|
|
|
|
local t = {}
|
|
|
|
for sub in str:gmatch("[^" .. sep .. "]+") do
|
|
|
|
table.insert(t, sub)
|
|
|
|
end
|
|
|
|
|
|
|
|
return t
|
|
|
|
end
|
|
|
|
|
2018-04-29 14:32:49 +00:00
|
|
|
-- Attempts to interpret the first of a list of tokens as a number.
|
2018-04-29 14:17:41 +00:00
|
|
|
function tryNumber(tokens)
|
|
|
|
local fst = table.remove(tokens, 1)
|
|
|
|
local qty = tonumber(fst)
|
|
|
|
|
|
|
|
if not qty then
|
|
|
|
table.insert(tokens, 1, fst)
|
|
|
|
end
|
|
|
|
|
|
|
|
return qty
|
|
|
|
end
|
|
|
|
|
2018-04-29 14:32:49 +00:00
|
|
|
-- Help text
|
2018-04-29 14:17:41 +00:00
|
|
|
local help = [[
|
|
|
|
Welcome to the Dragon CLI.
|
|
|
|
Commands:
|
|
|
|
w [name] - withdraw all items whose names contain [name]
|
|
|
|
w [qty] [name] - withdraw [qty] items whose names contain [name]
|
|
|
|
c - Craft item, using the turtle's inventory as a grid (turtle.craft)
|
|
|
|
d - Dump all items into storage
|
|
|
|
d [slot] - Dump items in [slot] into storage
|
|
|
|
r - Force connected storage server to reindex
|
|
|
|
help - Display this
|
|
|
|
This is an unstable version and does not support a GUI or multiple storage servers.]]
|
|
|
|
|
|
|
|
print "Dragon CLI"
|
|
|
|
while true do
|
|
|
|
write "|> "
|
|
|
|
local tokens = split(read(), " ")
|
|
|
|
local cmd = table.remove(tokens, 1)
|
|
|
|
|
|
|
|
if cmd == "w" then
|
|
|
|
local qty = tryNumber(tokens)
|
|
|
|
if not qty then
|
|
|
|
qty = math.huge
|
|
|
|
end
|
|
|
|
|
|
|
|
local item = table.concat(tokens, " ")
|
2018-04-29 15:55:15 +00:00
|
|
|
util.fetch(item, qty)
|
2018-04-29 14:17:41 +00:00
|
|
|
elseif cmd == "c" then
|
|
|
|
turtle.craft()
|
|
|
|
elseif cmd == "d" then
|
|
|
|
local slot = tryNumber(tokens)
|
|
|
|
|
|
|
|
if slot then dump(slot) else
|
|
|
|
local size = 16
|
|
|
|
if conf.introspection then size = conf.introspection.size() end
|
|
|
|
for i = 1, size do
|
2018-04-29 15:55:15 +00:00
|
|
|
util.dump(i)
|
2018-04-29 14:17:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
elseif cmd == "r" then
|
|
|
|
query { cmd = "reindex" }
|
|
|
|
elseif cmd == "help" then
|
|
|
|
textutils.pagedPrint(help)
|
|
|
|
end
|
|
|
|
end
|