utils: Add optional awful.util.deprecate options.
For now, only a `raw` option is implemented.
This commit is contained in:
parent
81f8a3085e
commit
e239492696
|
@ -37,7 +37,10 @@ util.shell = os.getenv("SHELL") or "/bin/sh"
|
||||||
local displayed_deprecations = {}
|
local displayed_deprecations = {}
|
||||||
--- Display a deprecation notice, but only once per traceback.
|
--- Display a deprecation notice, but only once per traceback.
|
||||||
-- @param[opt] see The message to a new method / function to use.
|
-- @param[opt] see The message to a new method / function to use.
|
||||||
function util.deprecate(see)
|
-- @tparam table args Extra arguments
|
||||||
|
-- @tparam boolean args.raw Print the message as-is without the automatic context
|
||||||
|
function util.deprecate(see, args)
|
||||||
|
args = args or {}
|
||||||
local tb = debug.traceback()
|
local tb = debug.traceback()
|
||||||
if displayed_deprecations[tb] then
|
if displayed_deprecations[tb] then
|
||||||
return
|
return
|
||||||
|
@ -49,7 +52,9 @@ function util.deprecate(see)
|
||||||
local funcname = info.name or "?"
|
local funcname = info.name or "?"
|
||||||
local msg = "awful: function " .. funcname .. " is deprecated"
|
local msg = "awful: function " .. funcname .. " is deprecated"
|
||||||
if see then
|
if see then
|
||||||
if string.sub(see, 1, 3) == 'Use' then
|
if args.raw then
|
||||||
|
msg = see
|
||||||
|
elseif string.sub(see, 1, 3) == 'Use' then
|
||||||
msg = msg .. ". " .. see
|
msg = msg .. ". " .. see
|
||||||
else
|
else
|
||||||
msg = msg .. ", see " .. see
|
msg = msg .. ", see " .. see
|
||||||
|
|
Loading…
Reference in New Issue