Skip to content

Commit

Permalink
capture cvar defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
ferronn-dev committed May 23, 2022
1 parent d3fae26 commit 28047ce
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
23 changes: 21 additions & 2 deletions spec/export_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@ describe('export', function()
local globalenv = {
C_Console = {
GetAllCommands = function()
return 'commands'
return {
{ command = 'foo' },
{ command = 'bar' },
{ command = 'baz' },
}
end,
},
C_CVar = {
GetCVarDefault = function(arg)
return 'default_' .. arg
end,
},
CreateFrame = function()
Expand All @@ -17,6 +26,7 @@ describe('export', function()
GetBuildInfo = function()
return 1, 2, 3, 4
end,
ipairs = ipairs,
LibStub = function()
return {
CompressDeflate = function(_, arg)
Expand All @@ -37,7 +47,16 @@ describe('export', function()
setfenv(loadfile('src/export.lua'), globalenv)('moo', addonenv)
local expected = {
BuildInfo = { 1, 2, 3, 4 },
ConsoleCommands = 'commands',
ConsoleCommands = {
{ command = 'foo' },
{ command = 'bar' },
{ command = 'baz' },
},
CVarDefaults = {
bar = 'default_bar',
baz = 'default_baz',
foo = 'default_foo',
},
Data = 'flatdump',
}
assert.same(expected, globalenv.TheFlatDumper)
Expand Down
8 changes: 8 additions & 0 deletions src/export.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,13 @@ local frame = _G.CreateFrame('Frame')
frame:RegisterEvent('PLAYER_LOGOUT')
frame:SetScript('OnEvent', function()
toexport.ConsoleCommands = _G.C_Console.GetAllCommands()
toexport.CVarDefaults = (function()
local t = {}
for _, command in ipairs(toexport.ConsoleCommands) do
local name = command.command
t[name] = _G.C_CVar.GetCVarDefault(name)
end
return t
end)()
_G.TheFlatDumper = _G.LibStub('LibDeflate'):CompressDeflate(G.pprint(toexport))
end)

0 comments on commit 28047ce

Please sign in to comment.