allow empty sections definition, fix error with previous commit

This commit is contained in:
Tangent / Rose / Nebula Rosa 2024-11-13 02:58:39 -07:00
parent 148afecb27
commit a7d5e1c31d

View File

@ -63,6 +63,10 @@ local function load_config(config_file_text)
config.base_url = config.first_section_url -- prevent errors due to required item being missing config.base_url = config.first_section_url -- prevent errors due to required item being missing
end end
if not config.sections then
config.sections = {} -- I've decided to allow empty sections (defaults to 1 section, for single story ebooks)
end
-- detecting manually specified sections and flagging it to the rest of the script -- detecting manually specified sections and flagging it to the rest of the script
if config.sections[1] then if config.sections[1] then
config.sections.start = 1 config.sections.start = 1
@ -75,6 +79,10 @@ local function load_config(config_file_text)
config.sections.start = 1 -- the first one can be optional since the common use case is ALL OF THEM config.sections.start = 1 -- the first one can be optional since the common use case is ALL OF THEM
end end
if not config.sections.finish then
config.sections.finish = 1
end
if #config.page_counts ~= config.sections.finish - config.sections.start + 1 then if #config.page_counts ~= config.sections.finish - config.sections.start + 1 then
error("Number of page_counts does not match number of sections.") error("Number of page_counts does not match number of sections.")
end end
@ -352,7 +360,7 @@ local function main(arguments)
local starting_point_reached = false local starting_point_reached = false
for _, action in ipairs(default_action_order) do for _, action in ipairs(default_action_order) do
if starting_point_reached then if starting_point_reached then
action(config) actions[action](config)
elseif action == arguments.action then elseif action == arguments.action then
starting_point_reached = true starting_point_reached = true
end end
@ -364,7 +372,7 @@ local function main(arguments)
end end
else else
for _, action in ipairs(default_action_order) do for _, action in ipairs(default_action_order) do
action(config) actions[action](config)
end end
end end
print("\nDone!\n") print("\nDone!\n")