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

Make --watch an option to select the watch engine #10

Merged
merged 2 commits into from
Sep 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/cluttex.lua
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ if options.watch then
watcher:close()
return true
end
elseif shellutil.has_command("fswatch") then
elseif shellutil.has_command("fswatch") and (options.watch == "auto" or options.watch == "fswatch") then
if CLUTTEX_VERBOSITY >= 2 then
message.info("Using `fswatch' command")
end
Expand All @@ -595,7 +595,7 @@ if options.watch then
end
return false
end
elseif shellutil.has_command("inotifywait") then
elseif shellutil.has_command("inotifywait") and (options.watch == "auto" or options.watch == "inotifywait") then
if CLUTTEX_VERBOSITY >= 2 then
message.info("Using `inotifywait' command")
end
Expand All @@ -620,7 +620,13 @@ if options.watch then
return false
end
else
message.error("Could not watch files because neither `fswatch' nor `inotifywait' was installed.")
if options.watch == "auto" then
message.error("Could not watch files because neither `fswatch' nor `inotifywait' was installed.")
elseif options.watch == "fswatch" then
message.error("Could not watch files because your selected engine `fswatch' was not installed.")
elseif options.watch == "inotifywait" then
message.error("Could not watch files because your selected engine `inotifywait' was not installed.")
end
message.info("See ClutTeX's manual for details.")
os.exit(1)
end
Expand Down
18 changes: 15 additions & 3 deletions src/texrunner/handleoption.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ Options:
cross-references. [default: 3]
--start-with-draft Start with draft mode.
--[no-]change-directory Change directory before running TeX.
--watch Watch input files for change. Requires fswatch
program to be installed.
--watch[=ENGINE] Watch input files for change. Requires fswatch
or inotifywait to be installed. ENGINE is one of
`fswatch', `inotifywait' or `auto' [default: `auto']
--tex-option=OPTION Pass OPTION to TeX as a single option.
--tex-options=OPTIONs Pass OPTIONs to TeX as multiple options.
--dvipdfmx-option[s]=OPTION[s] Same for dvipdfmx.
Expand Down Expand Up @@ -122,6 +123,8 @@ local option_spec = {
},
{
long = "watch",
param = true,
default = "auto",
},
{
short = "h",
Expand Down Expand Up @@ -312,7 +315,7 @@ local function handle_cluttex_options(arg)

elseif name == "watch" then
assert(options.watch == nil, "multiple --watch options")
options.watch = true
options.watch = param

elseif name == "help" then
usage(arg)
Expand Down Expand Up @@ -470,6 +473,15 @@ local function handle_cluttex_options(arg)

set_default_values(options)

-- parameter validy check TODO should this be organized as function like
-- set_default_values and with a key in the option spec (list or function)?
if options.watch then
if options.watch ~= "fswatch" and options.watch ~= "inotifywait" then
message.error("Unknown wait engine '", options.watch, "'.")
os.exit(1)
end
end

if options.output_format == "pdf" then
if options.check_driver ~= nil then
error("--check-driver can only be used when the output format is DVI.")
Expand Down