From 450c391faa866fae0536ad28e8b1fbf5a2a2df3c Mon Sep 17 00:00:00 2001 From: Tobias Ulmer Date: Tue, 16 Apr 2013 12:09:10 +0200 Subject: [PATCH] policy: remove e2lib.abort() handle_commandline_options() now return an err object Signed-off-by: Tobias Ulmer --- local/e2-build.lua | 4 ++-- local/e2-playground.lua | 4 ++-- local/policy.lua | 14 ++++++++++---- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/local/e2-build.lua b/local/e2-build.lua index c690852..f62a03b 100644 --- a/local/e2-build.lua +++ b/local/e2-build.lua @@ -92,9 +92,9 @@ local function e2_build(arg) local opts, arguments = e2option.parse(arg) -- get build mode from the command line - local build_mode = policy.handle_commandline_options(opts, true) + local build_mode, re = policy.handle_commandline_options(opts, true) if not build_mode then - return false, err.new("no build mode given") + return false, re end info, re = e2tool.collect_project_info(info) diff --git a/local/e2-playground.lua b/local/e2-playground.lua index 65f1d87..c91c4e0 100644 --- a/local/e2-playground.lua +++ b/local/e2-playground.lua @@ -53,9 +53,9 @@ local function e2_playground(arg) local opts, arguments = e2option.parse(arg) -- get build mode from the command line - local build_mode = policy.handle_commandline_options(opts, true) + local build_mode, re = policy.handle_commandline_options(opts, true) if not build_mode then - return false, err.new("no build mode given") + return false, re end info, re = e2tool.collect_project_info(info) if not info then diff --git a/local/policy.lua b/local/policy.lua index eef4f41..ded305b 100644 --- a/local/policy.lua +++ b/local/policy.lua @@ -222,7 +222,8 @@ end function policy.handle_commandline_options(opts, use_default) local default_build_mode_name = "tag" local nmodes = 0 - local mode = nil + local mode = false + if opts["build-mode"] then nmodes = nmodes + 1 end @@ -243,24 +244,30 @@ function policy.handle_commandline_options(opts, use_default) nmodes = nmodes + 1 end if nmodes > 1 then - e2lib.abort("Error: Multiple build modes are not supported") + return false, err.new("multiple build modes are not supported") end if not opts["build-mode"] and use_default then e2lib.warnf("WDEFAULT", "build-mode defaults to '%s'", default_build_mode_name) opts["build-mode"] = default_build_mode_name end + if opts["build-mode"] then if policy.default_build_mode(opts["build-mode"]) then mode = policy.default_build_mode(opts["build-mode"]) else - e2lib.abort("invalid build mode") + return false, err.new("invalid build mode") end if opts["build-mode"] == "release" then opts["check-remote"] = true opts["check"] = true end end + + if not mode then + return false, err.new("no build mode given") + end + return mode end @@ -307,7 +314,6 @@ function policy.default_build_mode(mode) deploy = false, } else - -- e2lib.abort("unknown default_build_mode mode=%s", tostring(mode)) return nil end end -- 2.39.5