end
--- Make sure the environment variables inside the globals table are
--- initialized properly, and abort otherwise.
--- This function always succeeds or aborts.
+-- initialized properly.
+-- @return True on success, false on error.
+-- @return Error object on failure.
function e2lib.init()
e2lib.log(4, "e2lib.init()")
-- DEBUG: change to "cr" to log return from function
for _, var in pairs(getenv) do
var.val = os.getenv(var.name)
if var.required and not var.val then
- e2lib.abort(string.format("%s is not set in the environment", var.name))
+ return false, err.new("%s is not set in the environment", var.name)
end
if var.default and not var.val then
var.val = var.default
-- get the host name
local hostname = io.popen("hostname")
if not hostname then
- e2lib.abort("execution of \"hostname\" failed")
+ return false, err.new("execution of \"hostname\" failed")
end
e2lib.globals.hostname = hostname:read("*a")
hostname:close()
if not e2lib.globals.hostname then
- e2lib.abort("hostname ist not set")
+ return false, err.new("hostname ist not set")
end
e2lib.globals.lock = lock.new()
+
+ return true
end
--- init2.
require("buildconfig")
local function e2_create_project(arg)
- e2lib.init()
+ local rc, re = e2lib.init()
+ if not rc then
+ return false, re
+ end
local opts, arguments = e2option.parse(arg)
if not opts then
require("buildconfig")
local function e2_fetch_project(arg)
- e2lib.init()
+ local rc, re = e2lib.init()
+ if not rc then
+ return false, re
+ end
local e = err.new("fetching project failed")
e2option.option("branch", "retrieve a specific project branch")
require("buildconfig")
local function e2_install_e2(arg)
- e2lib.init()
+ local rc, re = e2lib.init()
+ if not rc then
+ return false, re
+ end
local opts, arguments = e2option.parse(arg)
if not opts then
require("e2util")
local function e2(arg)
- e2lib.init()
+ local rc, re = e2lib.init()
+ if not rc then
+ return false, re
+ end
e2option.flag("prefix", "print installation prefix",
function()
local err = require("err")
local function e2_build_numbers(arg)
- e2lib.init()
+ local rc, re = e2lib.init()
+ if not rc then
+ return false, re
+ end
+
local info, re = e2tool.local_init(nil, "build-numbers")
if not info then
return false, re
local policy = require("policy")
local function e2_build(arg)
- e2lib.init()
+ local rc, re = e2lib.init()
+ if not rc then
+ return false, re
+ end
+
local info, re = e2tool.local_init(nil, "build")
if not info then
return false, re
end
local function e2_cf(arg)
- e2lib.init()
+ local rc, re = e2lib.init()
+ if not rc then
+ return false, re
+ end
+
local info, re = e2tool.local_init(nil, "cf")
if not info then
return false, re
local e2option = require("e2option")
local function e2_dlist(arg)
- e2lib.init()
+ local rc, re = e2lib.init()
+ if not rc then
+ return false, re
+ end
+
local info, re = e2tool.local_init(nil, "dlist")
if not info then
return false, re
local e2option = require("e2option")
local function e2_dsort(arg)
- e2lib.init()
+ local rc, re = e2lib.init()
+ if not rc then
+ return false, re
+ end
+
local info, re = e2tool.local_init(nil, "dsort")
if not info then
return false, re
local scm = require("scm")
local function e2_fetch_source(arg)
- e2lib.init()
+ local rc, re = e2lib.init()
+ if not rc then
+ return false, re
+ end
+
local info, re = e2tool.local_init(nil, "fetch-sources")
if not info then
return false, re
-- @return Error object on failure.
local function e2_help(arg)
local rc, re, e
- e2lib.init()
+ rc, re = e2lib.init()
+ if not rc then
+ return false, re
+ end
local info, re = e2tool.local_init(nil, "help")
if not info then
local policy = require("policy")
local function e2_ls_project(arg)
- e2lib.init()
+ local rc, re = e2lib.init()
+ if not rc then
+ return false, re
+ end
+
local info, re = e2tool.local_init(nil, "ls-project")
if not info then
return false, re
end
local function e2_new_source(arg)
- e2lib.init()
+ local rc, re = e2lib.init()
+ if not rc then
+ return false, re
+ end
+
local info, re = e2tool.local_init(nil, "new-source")
if not info then
return false, re
local policy = require("policy")
local function e2_playground(arg)
- e2lib.init()
+ local rc, re = e2lib.init()
+ if not rc then
+ return false, re
+ end
+
local info, re = e2tool.local_init(nil, "playground")
if not info then
return false, re