• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

sile-typesetter / sile / 13970693754

20 Mar 2025 01:37PM UTC coverage: 31.5% (+2.0%) from 29.463%
13970693754

push

github

web-flow
Merge pull request #2241 from alerque/path-docs

Improve 3rd party module usage prompt

2 of 6 new or added lines in 2 files covered. (33.33%)

472 existing lines in 3 files now uncovered.

6301 of 20003 relevant lines covered (31.5%)

4211.63 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/core/cli.lua
1
local cli = pl.class()
×
2

3
cli.parseArguments = function ()
4
   local cliargs = require("cliargs")
×
5
   local print_version = function (flag)
6
      print(flag == "V" and "SILE " .. SILE.version or SILE.full_version)
×
7
      os.exit(0)
×
8
   end
9
   cliargs:set_colsz(0, 120)
×
10
   cliargs:set_name("sile")
×
11
   cliargs:set_description([[
×
12
      The SILE typesetter reads an input file(s), by default in either SIL or XML format, and
13
      processes them to generate an output file, by default in PDF format. The output will be written
14
      to a file with the same name as the first input file with the extension changed to .pdf unless
15
      the `--output` argument is used. Additional input or output formats can be handled by loading
16
      a module with the `--use` argument to add support for them first.
17
    ]])
×
18
   cliargs:splat("INPUTS", "Input document filename(s), by default in SIL, XML, or Lua formats.", nil, 999)
×
19
   cliargs:option("-b, --backend=VALUE", "Specify the output backend")
×
20
   cliargs:option("-c, --class=VALUE", "Override the default or specified document class")
×
21
   cliargs:option("-d, --debug=VALUE", "Show debug information for tagged aspects of SILE’s operation", {})
×
22
   cliargs:option("-e, --evaluate=VALUE", "Evaluate Lua expression before processing input", {})
×
23
   cliargs:option("-E, --evaluate-after=VALUE", "Evaluate Lua expression after processing input", {})
×
24
   cliargs:option("-f, --fontmanager=VALUE", "Specify which font manager to use")
×
25
   cliargs:option("-I, --include=FILE", "Deprecated, see --use, --preamble, --postamble, or multiple input files", {})
×
NEW
26
   cliargs:option(
×
27
      "    --luarocks-tree=LUAROCKS_TREE",
28
      "Add a path to the list of LuaRocks trees searched for modules",
29
      {}
30
   )
31
   cliargs:option("-m, --makedeps=FILE", "Generate a Makefile format list of dependencies and white them to a file")
×
32
   cliargs:option("-o, --output=FILE", "Explicitly set output file name")
×
33
   cliargs:option("-O, --options=PARAMETER=VALUE[,PARAMETER=VALUE]", "Set or override document class options", {})
×
34
   cliargs:option(
×
35
      "-p, --preamble=FILE",
36
      "Include the contents of a SIL, XML, or other resource file before the input document content",
37
      {}
38
   )
39
   cliargs:option(
×
40
      "-P, --postamble=FILE",
41
      "Include the contents of a SIL, XML, or other resource file after the input document content",
42
      {}
43
   )
44
   cliargs:option(
×
45
      "-u, --use=MODULE[[PARAMETER=VALUE][,PARAMETER=VALUE]]",
46
      "Load and initialize a class, inputter, shaper, or other module before processing the main input",
47
      {}
48
   )
49
   cliargs:flag("-q, --quiet", "Suppress warnings and informational messages during processing")
×
50
   cliargs:flag("-t, --traceback", "Display detailed location trace on errors and warnings")
×
51
   cliargs:flag("-h, --help", "Display this help, then exit")
×
52
   cliargs:flag("-V, --version", "Print version", print_version)
×
53
   -- Work around cliargs not processing - as an alias for STDIO streams:
54
   -- https://github.com/amireh/lua_cliargs/issues/67
55
   local _arg = pl.tablex.imap(luautf8.gsub, _G.arg, "^-$", "STDIO")
×
56
   local opts, parse_err = cliargs:parse(_arg)
×
57
   if not opts and parse_err then
×
58
      print(parse_err)
×
59
      local code = parse_err:match("^Usage:") and 0 or 1
×
60
      os.exit(code)
×
61
   end
62
   if opts.INPUTS and #opts.INPUTS > 0 then
×
63
      local has_input_filename = false
×
64
      pl.tablex.foreachi(opts.INPUTS, function (v, k)
×
65
         if v == "STDIO" then
×
66
            opts.INPUTS[k] = "-"
×
67
         elseif not has_input_filename then
×
68
            has_input_filename = true
×
69
         end
70
      end)
71
      if not has_input_filename and not opts.output then
×
72
         SU.error([[
×
73
            Unable to derive an output filename (perhaps because input is a STDIO stream)
74

75
            Please use --output to set one explicitly.
76
         ]])
×
77
      end
78
      SILE.input.filenames = opts.INPUTS
×
79
   end
80
   if opts.backend then
×
81
      SILE.input.backend = opts.backend
×
82
   end
83
   if opts.class then
×
84
      SILE.input.class = opts.class
×
85
   end
86
   for _, flags in ipairs(opts.debug) do
×
87
      for _, flag in ipairs(pl.stringx.split(flags, ",")) do
×
88
         SILE.debugFlags[flag] = true
×
89
      end
90
   end
91
   for _, statement in ipairs(opts["evaluate"]) do
×
92
      table.insert(SILE.input.evaluates, statement)
×
93
   end
94
   for _, statement in ipairs(opts["evaluate-after"]) do
×
95
      table.insert(SILE.input.evaluateAfters, statement)
×
96
   end
97
   if opts.fontmanager then
×
98
      SILE.input.fontmanager = opts.fontmanager
×
99
   end
NEW
100
   for _, tree in ipairs(opts["luarocks-tree"]) do
×
NEW
101
      table.insert(SILE.input.luarocksTrees, tree)
×
102
   end
103
   if opts.makedeps then
×
104
      SILE.makeDeps = require("core.makedeps")
×
105
      SILE.makeDeps.filename = opts.makedeps
×
106
   end
107
   if opts.output then
×
108
      if opts.output == "STDIO" then
×
109
         opts.output = "-"
×
110
      end
111
      SILE.outputFilename = opts.output
×
112
   end
113
   for _, option in ipairs(opts.options) do
×
114
      local options = SILE.parserBits.parameters:match(option)
×
115
      SILE.input.options = pl.tablex.merge(SILE.input.options, options, true)
×
116
   end
117
   for _, use in ipairs(opts.use) do
×
118
      local spec = SILE.parserBits.cliuse:match(use)
×
119
      table.insert(SILE.input.uses, spec)
×
120
   end
121
   for _, path in ipairs(opts.preamble) do
×
122
      table.insert(SILE.input.preambles, path)
×
123
   end
124
   for _, path in ipairs(opts.postamble) do
×
125
      table.insert(SILE.input.postambles, path)
×
126
   end
127
   if #opts.include > 0 then
×
128
      SU.deprecated("-I/--include", "-u/--use or -p/--preamble", "0.14.0", "0.15.0")
×
129
   end
130
   -- http://lua-users.org/wiki/VarargTheSecondClassCitizen
131
   local summary = function (...)
132
      local contentloc = SILE.traceStack:locationHead()
×
133
      local codeloc = pl.utils.unpack({ ... }, 1, select("#", ...))
×
134
      return ("Processing at: %s\n\tUsing code at: %s"):format(contentloc, codeloc)
×
135
   end
136
   local unexpected = function ()
137
      if not SILE.scratch.caughterror then
×
138
         io.stderr:write("\n! Unexpected Lua error\n")
×
139
      end
140
   end
141
   local trace = function (...)
142
      unexpected()
×
143
      io.stderr:write(debug.traceback("", 2) or "\t! debug.traceback() did not identify code location")
×
144
      io.stderr:write("\n")
×
145
      return summary(...)
×
146
   end
147
   local identity = function (...)
148
      unexpected()
×
149
      return summary(...) .. "\n\nRun with --traceback for more detailed trace leading up to errors."
×
150
   end
151
   SILE.errorHandler = opts.traceback and trace or identity
×
152
   SILE.quiet = opts.quiet
×
153
   SILE.traceback = opts.traceback
×
154
end
155

156
return cli
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc