feat: cube ls

This commit is contained in:
Guillaume ARM 2022-07-18 02:25:30 +02:00
parent f880a577a4
commit 12278f72e9
4 changed files with 23 additions and 6 deletions

View File

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.cuberc
.cubestartup

View File

@ -1,4 +1,4 @@
local _VERSION = '1.1.0';
local _VERSION = '1.2.0';
local CUBE_CHANNEL = 64;
local net = require('/apis/net')();
@ -132,14 +132,29 @@ local COMMANDS = {
end
end,
ls = function()
print('TODO: ls');
local ok, results, packets = net.sendMultipleRequests(CUBE_CHANNEL, 'ping', 'ping');
if not ok then
error(results);
end
for k in ipairs(results) do
local result = results[k];
local packet = packets[k];
print("=> " .. tostring(packet.sourceId)
..
(
packet.sourceLabel and " (label=" .. tostring(packet.sourceLabel) .. ")" or
"") .. ": startup='" .. result.startup .. "'");
end
end,
configure = function()
if not isConfigFileExists() then
print('Error: unable to configure because \'.cuberc\' file is missing\nTry: \'cube init\' command')
return;
end
print('TODO: configure');
print('not implemented yet.');
end,
["set-startup"] = function(machineId, shellCommand)
if not isConfigFileExists() then
@ -174,7 +189,7 @@ local COMMANDS = {
return;
end
print('TODO: deploy.');
print('not implemented yet.');
end,
version = function()
print('cube client v' .. _VERSION);

View File

@ -1,4 +1,4 @@
local _VERSION = '1.0.0';
local _VERSION = '1.1.0';
local function trim(s)
return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
@ -17,7 +17,7 @@ local function readFile(path)
return contents
end
local startupCommand = trim(readFile('.cubestartup') or "");
local startupCommand = trim(readFile('.cubestartup') or readFile('.cubestart') or "");
if startupCommand ~= "" then