Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config file #16

Closed
atticus-sullivan opened this issue Dec 16, 2024 · 4 comments · Fixed by #22 or #26
Closed

Config file #16

atticus-sullivan opened this issue Dec 16, 2024 · 4 comments · Fixed by #22 or #26
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@atticus-sullivan
Copy link
Owner

Add the functionality to read options from a config file instead of/before reading CLI arguments.

Combined with #15 we could decide to allow (or even force) for the installation of hooks via this config file by requiring the config file being a lua script (similar to l3build.

Remember: Some options can be passed more than once and accumulate in the process (e.g. glossaries I think) in the config file we'd need to make these an array.

@atticus-sullivan atticus-sullivan self-assigned this Dec 16, 2024
@atticus-sullivan atticus-sullivan added the enhancement New feature or request label Dec 16, 2024
@atticus-sullivan atticus-sullivan mentioned this issue Dec 16, 2024
atticus-sullivan added a commit that referenced this issue Dec 17, 2024
…t handling

This is a preparation for #16. Doing this refactor I learnt that cluttex
(and thus also cluttealtex) parses arguments which have a default value
quite weird.
If default is set and parameter is specified as --opt=param, the
parameter from the argument is taken.
If default is set and parameter is specified as --opt param, the default
paramter is taken and the cli parameter is ignored (probably produces an
error later during parsing).

The main part of the refactor was
1. move the option_spec to its own file
2. move handling the options inside the option_spec table
3. generate LUT to avoid having to iterate over the complete table

Now when adding a new option all that needs to be done is in the
option_spec.lua file (adding the entry in the table and appending to the
usage output).
@atticus-sullivan
Copy link
Owner Author

Maybe the config file could even define new cli arguments (e.g. to define abbreviations like --final which disables quiet and disables memoization) 🤔

@atticus-sullivan
Copy link
Owner Author

One idea to read in the config file/script:

	-- Parse options from config file
	if fsutil.isfile(".cluttealtexrc.lua") then
		-- see https://ref.coddy.tech/lua/lua-sandboxing
		-- for us the main purpose is to avoid the config modifies the
		-- environment we're working in.
		-- Apart from that restriction, the config is allowed to execute
		-- anything.
		-- local sandbox = {
		-- 	print   = print,
		-- 	-- Add other functions here
		-- }
		-- setmetatable(sandbox, {__index = function(t:table, k:any)
		-- 	return error("Forbidden function/variable", 2) -- TODO deep-copy from _G on demand instead
		-- end})
		-- TODO move to a lua file to make use of _G (dynamically copy over/return on __index)
		local cfgChunk, err = loadfile(".cluttealtexrc.lua")
		if err then
			message.error("Error loading the config file '.cluttealtexrc.lua'")
			error(err)
		end
		local cfg: table
		do
			cfg = cfgChunk() as table
		end
		print(cfg.options)
		print(cfg.defaults)
	end

the goal eventually is to sandbox reading the config as much as possible. For now as a proof of concept, I'd say we keep it in the global state and avoid splitting into a new .lua (no teal) file.

@atticus-sullivan atticus-sullivan linked a pull request Dec 18, 2024 that will close this issue
3 tasks
@atticus-sullivan atticus-sullivan added this to the v0.9.9 milestone Dec 22, 2024
@atticus-sullivan
Copy link
Owner Author

Question: How to handle all the watch related stuff. Via cli, the order is important but via cfg it's a table without strict ordering -> leads to non-determinism 👎

  • Add an option to forbid setting an option directly via string from the cfg?
  • Add an option to directly set the include/exclude paths for watch?

@atticus-sullivan
Copy link
Owner Author

Also --package-support should be accumulating

@atticus-sullivan atticus-sullivan linked a pull request Dec 27, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
1 participant