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

sile-typesetter / sile / 14860011647

06 May 2025 12:44PM UTC coverage: 67.057% (+32.5%) from 34.559%
14860011647

push

github

alerque
chore(typesetters): Fixup access to class from typesetter functions

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

1344 existing lines in 103 files now uncovered.

14880 of 22190 relevant lines covered (67.06%)

11549.16 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 a preset combination of backend modules to use")
×
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, --outputter=VALUE", "Specify which outputter to use")
×
25
   cliargs:option("-s, --shaper=VALUE", "Specify which shaper to use")
×
26
   cliargs:option("-f, --fontmanager=VALUE", "Specify which font manager to use")
×
UNCOV
27
   cliargs:option("-I, --include=FILE", "Deprecated, see --use, --preamble, --postamble, or multiple input files", {})
×
UNCOV
28
   cliargs:option(
×
29
      "    --luarocks-tree=LUAROCKS_TREE",
30
      "Add a path to the list of LuaRocks trees searched for modules",
31
      {}
32
   )
33
   cliargs:option("-m, --makedeps=FILE", "Generate a Makefile format list of dependencies and white them to a file")
×
34
   cliargs:option("-o, --output=FILE", "Explicitly set output file name")
×
UNCOV
35
   cliargs:option("-O, --options=PARAMETER=VALUE[,PARAMETER=VALUE]", "Set or override document class options", {})
×
UNCOV
36
   cliargs:option(
×
37
      "-p, --preamble=FILE",
38
      "Include the contents of a SIL, XML, or other resource file before the input document content",
39
      {}
40
   )
UNCOV
41
   cliargs:option(
×
42
      "-P, --postamble=FILE",
43
      "Include the contents of a SIL, XML, or other resource file after the input document content",
44
      {}
45
   )
UNCOV
46
   cliargs:option(
×
47
      "-u, --use=MODULE[[PARAMETER=VALUE][,PARAMETER=VALUE]]",
48
      "Load and initialize a class, inputter, shaper, or other module before processing the main input",
49
      {}
50
   )
51
   cliargs:flag("-q, --quiet", "Suppress warnings and informational messages during processing")
×
52
   cliargs:flag("-t, --traceback", "Display detailed location trace on errors and warnings")
×
UNCOV
53
   cliargs:flag("-h, --help", "Display this help, then exit")
×
UNCOV
54
   cliargs:flag("-V, --version", "Print version", print_version)
×
55
   -- Work around cliargs not processing - as an alias for STDIO streams:
56
   -- https://github.com/amireh/lua_cliargs/issues/67
57
   local _arg = pl.tablex.imap(luautf8.gsub, _G.arg, "^-$", "STDIO")
×
58
   local opts, parse_err = cliargs:parse(_arg)
×
59
   if not opts and parse_err then
×
60
      print(parse_err)
×
UNCOV
61
      local code = parse_err:match("^Usage:") and 0 or 1
×
62
      os.exit(code)
×
63
   end
64
   if opts.INPUTS and #opts.INPUTS > 0 then
×
65
      local has_input_filename = false
×
66
      pl.tablex.foreachi(opts.INPUTS, function (v, k)
×
67
         if v == "STDIO" then
×
68
            opts.INPUTS[k] = "-"
×
UNCOV
69
         elseif not has_input_filename then
×
UNCOV
70
            has_input_filename = true
×
71
         end
72
      end)
UNCOV
73
      if not has_input_filename and not opts.output then
×
UNCOV
74
         SU.error([[
×
75
            Unable to derive an output filename (perhaps because input is a STDIO stream)
76

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

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

© 2025 Coveralls, Inc