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

sile-typesetter / sile / 14056548964

25 Mar 2025 09:49AM UTC coverage: 56.745% (+23.9%) from 32.874%
14056548964

push

github

web-flow
Merge pull request #2244 from alerque/space-shaping

Fixup flexible space creation logic

8 of 8 new or added lines in 2 files covered. (100.0%)

75 existing lines in 3 files now uncovered.

12203 of 21505 relevant lines covered (56.74%)

2774.49 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", {})
×
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
100
   for _, tree in ipairs(opts["luarocks-tree"]) do
×
101
      table.insert(SILE.input.luarocksTrees, tree)
×
102
   end
103
   if opts.makedeps then
×
104
      SILE.input.makedeps = opts.makedeps
×
105
   end
UNCOV
106
   if opts.output then
×
107
      if opts.output == "STDIO" then
×
108
         opts.output = "-"
×
109
      end
UNCOV
110
      SILE.outputFilename = opts.output
×
111
   end
UNCOV
112
   for _, option in ipairs(opts.options) do
×
113
      local options = SILE.parserBits.parameters:match(option)
×
114
      SILE.input.options = pl.tablex.merge(SILE.input.options, options, true)
×
115
   end
UNCOV
116
   for _, use in ipairs(opts.use) do
×
117
      local spec = SILE.parserBits.cliuse:match(use)
×
118
      table.insert(SILE.input.uses, spec)
×
119
   end
UNCOV
120
   for _, path in ipairs(opts.preamble) do
×
121
      table.insert(SILE.input.preambles, path)
×
122
   end
UNCOV
123
   for _, path in ipairs(opts.postamble) do
×
124
      table.insert(SILE.input.postambles, path)
×
125
   end
UNCOV
126
   if #opts.include > 0 then
×
127
      SU.deprecated("-I/--include", "-u/--use or -p/--preamble", "0.14.0", "0.15.0")
×
128
   end
129
   -- http://lua-users.org/wiki/VarargTheSecondClassCitizen
130
   local summary = function (...)
UNCOV
131
      local contentloc = SILE.traceStack:locationHead()
×
132
      local codeloc = pl.utils.unpack({ ... }, 1, select("#", ...))
×
133
      return ("Processing at: %s\n\tUsing code at: %s"):format(contentloc, codeloc)
×
134
   end
135
   local unexpected = function ()
UNCOV
136
      if not SILE.scratch.caughterror then
×
137
         io.stderr:write("\n! Unexpected Lua error\n")
×
138
      end
139
   end
140
   local trace = function (...)
UNCOV
141
      unexpected()
×
142
      io.stderr:write(debug.traceback("", 2) or "\t! debug.traceback() did not identify code location")
×
143
      io.stderr:write("\n")
×
144
      return summary(...)
×
145
   end
146
   local identity = function (...)
UNCOV
147
      unexpected()
×
148
      return summary(...) .. "\n\nRun with --traceback for more detailed trace leading up to errors."
×
149
   end
UNCOV
150
   SILE.errorHandler = opts.traceback and trace or identity
×
151
   SILE.quiet = opts.quiet
×
152
   SILE.traceback = opts.traceback
×
153
end
154

UNCOV
155
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