From 68ad4f5fcd99f85e046cd2f5460c46c238aadb2e Mon Sep 17 00:00:00 2001 From: Tobias Ulmer Date: Mon, 20 Aug 2012 11:37:28 +0200 Subject: [PATCH] Remove opts.arguments and access arguments directly Signed-off-by: Tobias Ulmer --- generic/e2option.lua | 3 --- global/e2-create-project.lua | 6 +++--- global/e2-fetch-project.lua | 12 ++++++------ global/e2-install-e2.lua | 4 ++-- local/build.lua | 8 ++++---- local/cf.lua | 8 ++++---- local/dlist.lua | 8 ++++---- local/fetch-sources.lua | 8 ++++---- local/ls-project.lua | 6 +++--- local/new-source.lua | 12 ++++++------ local/playground.lua | 6 +++--- 11 files changed, 39 insertions(+), 42 deletions(-) diff --git a/generic/e2option.lua b/generic/e2option.lua index 2426a00..ca65e67 100644 --- a/generic/e2option.lua +++ b/generic/e2option.lua @@ -318,9 +318,6 @@ function e2option.parse(args) defaultoptions() local opts = {} local vals = {} - -- arguments is a special option containing all additional arguments that - -- are not parsed. XXX: Remove this if possible. - opts["arguments"] = vals userdefaultoptions(opts) diff --git a/global/e2-create-project.lua b/global/e2-create-project.lua index a4a9b59..2c78449 100644 --- a/global/e2-create-project.lua +++ b/global/e2-create-project.lua @@ -43,7 +43,7 @@ Create a new project and store it on in . e2option.documentation = string.format(doc, e2lib.globals.default_projects_server) -local opts = e2option.parse(arg) +local opts, arguments = e2option.parse(arg) local rc, e = e2lib.read_global_config() if not rc then e2lib.abort(e) @@ -76,11 +76,11 @@ else e2lib.globals.local_e2_tag = config.site.e2_tag end -if #opts.arguments ~= 1 then +if #arguments ~= 1 then e2option.usage(1) end -local sl, re = e2lib.parse_server_location(opts.arguments[1], +local sl, re = e2lib.parse_server_location(arguments[1], e2lib.globals.default_projects_server) if not sl then e2lib.abort(e:cat(re)) diff --git a/global/e2-fetch-project.lua b/global/e2-fetch-project.lua index 6ee572f..005c69b 100644 --- a/global/e2-fetch-project.lua +++ b/global/e2-fetch-project.lua @@ -47,7 +47,7 @@ e2option.documentation = string.format(doc, e2option.option("branch", "retrieve a specific project branch") e2option.option("tag", "retrieve a specific project tag") -local opts = e2option.parse(arg) +local opts, arguments = e2option.parse(arg) local rc, re = e2lib.read_global_config() if not rc then e2lib.abort(e:cat(re)) @@ -65,14 +65,14 @@ end -- standard global tool setup finished -if #opts.arguments < 1 then +if #arguments < 1 then e2lib.abort("specify path to a project to fetch") end -if #opts.arguments > 2 then +if #arguments > 2 then e2lib.abort("too many arguments") end -local sl, re = e2lib.parse_server_location(opts.arguments[1], +local sl, re = e2lib.parse_server_location(arguments[1], e2lib.globals.default_projects_server) if not sl then e2lib.abort(e:cat(re)) @@ -82,8 +82,8 @@ local p = {} p.server = sl.server p.location = sl.location p.name = e2lib.basename(p.location) -if opts.arguments[2] then - p.destdir = opts.arguments[2] +if arguments[2] then + p.destdir = arguments[2] else p.destdir = p.name end diff --git a/global/e2-install-e2.lua b/global/e2-install-e2.lua index d863578..1f24195 100644 --- a/global/e2-install-e2.lua +++ b/global/e2-install-e2.lua @@ -39,7 +39,7 @@ usage: e2-install-e2 [OPTION ...] Installs local tools in project environment. ]] -local opts = e2option.parse(arg) +local opts, arguments = e2option.parse(arg) local root = e2lib.locate_project_root() if not root then @@ -71,7 +71,7 @@ end -- standard global tool setup finished -if #opts.arguments > 0 then +if #arguments > 0 then e2option.usage(1) end diff --git a/local/build.lua b/local/build.lua index ff97d45..987f77d 100644 --- a/local/build.lua +++ b/local/build.lua @@ -92,7 +92,7 @@ e2option.option("disable-writeback", "disable writeback for server", nil, e2option.option("enable-writeback", "enable writeback for server", nil, enable_writeback, "SERVER") -local opts = e2option.parse(arg) +local opts, arguments = e2option.parse(arg) -- get build mode from the command line local build_mode = policy.handle_commandline_options(opts, true) @@ -121,8 +121,8 @@ if opts["all"] then for r,_ in pairs(info.results) do table.insert(results, r) end -elseif #opts.arguments > 0 then - for i,r in ipairs(opts.arguments) do +elseif #arguments > 0 then + for i,r in ipairs(arguments) do table.insert(results, r) end end @@ -148,7 +148,7 @@ if playground then if opts.all then e2lib.abort("--all and --playground are mutually exclusive") end - if #opts.arguments ~= 1 then + if #arguments ~= 1 then e2lib.abort("please select one single result for the playground") end end diff --git a/local/cf.lua b/local/cf.lua index fcb362d..f478808 100644 --- a/local/cf.lua +++ b/local/cf.lua @@ -57,7 +57,7 @@ e.g.: eb is equivalent to editbuildscript modify and create configuration files ]] -local opts = e2option.parse(arg) +local opts, arguments = e2option.parse(arg) -- initialize some basics in the info structure without actually loading -- the project configuration. @@ -212,8 +212,8 @@ commands.esource = editsource local i = 1 local match = {} -local cmd = opts.arguments[1] -if #opts.arguments < 1 then +local cmd = arguments[1] +if #arguments < 1 then e2option.usage() e2lib.finish(1) end @@ -224,7 +224,7 @@ for c,f in pairs(commands) do end if #match == 1 then local a = {} - for _,o in ipairs(opts.arguments) do + for _,o in ipairs(arguments) do table.insert(a, o) end local f = commands[match[1]] diff --git a/local/dlist.lua b/local/dlist.lua index 570b933..44d16bc 100644 --- a/local/dlist.lua +++ b/local/dlist.lua @@ -45,13 +45,13 @@ for the given result show those results which it depends on ]] e2option.flag("recursive", "show indirect dependencies, too") -local opts = e2option.parse(arg) +local opts, arguments = e2option.parse(arg) -if #opts.arguments == 0 then +if #arguments == 0 then e2lib.abort("no result given - enter `e2-dlist --help' for usage information") -elseif #opts.arguments ~= 1 then e2option.usage(1) end +elseif #arguments ~= 1 then e2option.usage(1) end -local result = opts.arguments[1] +local result = arguments[1] info, re = e2tool.collect_project_info(info) if not info then e2lib.abort(re) diff --git a/local/fetch-sources.lua b/local/fetch-sources.lua index 3d5fbed..ef53f27 100644 --- a/local/fetch-sources.lua +++ b/local/fetch-sources.lua @@ -73,7 +73,7 @@ e2option.flag("update", "update selected source") e2option.flag("source", "select sources by source names (default)") e2option.flag("result", "select sources by result names") -local opts = e2option.parse(arg) +local opts, arguments = e2option.parse(arg) info, re = e2tool.collect_project_info(info) if not info then e2lib.abort(re) @@ -90,7 +90,7 @@ end if opts.all then e2lib.warn("WOTHER", "--all selects all sources, even files sources") end -if #opts.arguments > 0 then +if #arguments > 0 then opts.selection = true end if not (opts.scm or opts.files or opts.chroot or opts.selection @@ -192,8 +192,8 @@ end local sel = {} -- selected sources -if #opts.arguments > 0 then - for _, x in pairs(opts.arguments) do +if #arguments > 0 then + for _, x in pairs(arguments) do if info.sources[x] and not opts.result then e2lib.log(3, "is regarded as source: " .. x) sel[x] = x diff --git a/local/ls-project.lua b/local/ls-project.lua index 4659580..7381e88 100644 --- a/local/ls-project.lua +++ b/local/ls-project.lua @@ -50,7 +50,7 @@ e2option.flag("dot-sources", "generate dot(1) graph with sources included") e2option.flag("swap", "swap arrow directions in dot graph") e2option.flag("all", "show unused results and sources, too") -local opts = e2option.parse(arg) +local opts, arguments = e2option.parse(arg) info, re = e2tool.collect_project_info(info) if not info then @@ -66,8 +66,8 @@ if opts.all then for r, _ in pairs(info.results) do table.insert(results, r) end -elseif #opts.arguments > 0 then - for _, r in ipairs(opts.arguments) do +elseif #arguments > 0 then + for _, r in ipairs(arguments) do if info.results[r] then table.insert(results, r) else diff --git a/local/new-source.lua b/local/new-source.lua index 3c01e78..caf4184 100644 --- a/local/new-source.lua +++ b/local/new-source.lua @@ -66,7 +66,7 @@ e2option.flag("git", "create a git repository") e2option.flag("files", "create a new file on a files server") e2option.option("server", "specify server") e2option.flag("no-checksum", "don't verify checksum") -local opts = e2option.parse(arg) +local opts, arguments = e2option.parse(arg) -- read a checksum from a file -- @param checksum_file string: the file containing the checksums @@ -257,7 +257,7 @@ if not info then end if opts.git then - if #opts.arguments ~= 1 then + if #arguments ~= 1 then e2lib.abort(" argument required") end -- remote @@ -265,7 +265,7 @@ if opts.git then if opts["server"] then rserver = opts["server"] end - local name = opts.arguments[1] + local name = arguments[1] local rlocation = string.format("%s/git/%s.git", info.project_location, name) -- local local lserver = info.root_server_name @@ -279,15 +279,15 @@ if opts.git then e2lib.log(1, "See e2-new-source(1) to see how to go on") elseif opts.files then - local location = opts.arguments[1] + local location = arguments[1] local sl, e = e2lib.parse_server_location(location, info.default_files_server) if not sl then e2lib.abort(e) end local server = sl.server local location = sl.location - local source_file = opts.arguments[2] - local checksum_file = opts.arguments[3] + local source_file = arguments[2] + local checksum_file = arguments[3] local checksum_file_format = opts["checksum-file"] local no_checksum = opts["no-checksum"] if not no_checksum and not checksum_file then diff --git a/local/playground.lua b/local/playground.lua index 96cb94a..dc5b440 100644 --- a/local/playground.lua +++ b/local/playground.lua @@ -51,7 +51,7 @@ e2option.option("command","execute command in chroot") e2option.flag("runinit","run init files automatically") e2option.flag("showpath", "prints the path of the build directory inside the chroot to stdout" ) -local opts = e2option.parse(arg) +local opts, arguments = e2option.parse(arg) -- get build mode from the command line local build_mode = policy.handle_commandline_options(opts, true) if not build_mode then @@ -66,11 +66,11 @@ if not rc then e2lib.abort(re) end -if #opts.arguments ~= 1 then +if #arguments ~= 1 then e2option.usage(1) end -r = opts.arguments[1] +r = arguments[1] -- apply the standard build mode to all results for _,res in pairs(info.results) do -- 2.39.5