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

sile-typesetter / sile / 9304060604

30 May 2024 02:07PM UTC coverage: 74.124% (-0.6%) from 74.707%
9304060604

push

github

alerque
style: Reformat Lua with stylua

8104 of 11995 new or added lines in 184 files covered. (67.56%)

15 existing lines in 11 files now uncovered.

12444 of 16788 relevant lines covered (74.12%)

7175.1 hits per line

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

65.59
/core/cli.lua
1
local cli = pl.class()
181✔
2

3
cli.parseArguments = function ()
4
   local cliargs = require("cliargs")
181✔
5
   local print_version = function ()
NEW
6
      print(SILE.full_version)
×
NEW
7
      os.exit(0)
×
8
   end
9
   cliargs:set_colsz(0, 120)
181✔
10
   cliargs:set_name("sile")
181✔
11
   cliargs:set_description([[
362✔
12
      The SILE typesetter reads a single input file, by default in either SIL or XML format,
13
      and processes it to generate a single output file, by default in PDF format. The
14
      output file will be written to the same name as the input file with the extension
15
      changed to .pdf. Additional input or output formats can be handled by requiring a
16
      module that adds support for them first.
17
    ]])
181✔
18
   cliargs:splat("INPUTS", "input document(s), by default in SIL or XML format", nil, 999)
181✔
19
   cliargs:option("-b, --backend=VALUE", "choose an alternative output backend")
181✔
20
   cliargs:option("-c, --class=VALUE", "override default document class")
181✔
21
   cliargs:option("-d, --debug=VALUE", "show debug information for tagged aspects of SILE’s operation", {})
181✔
22
   cliargs:option("-e, --evaluate=VALUE", "evaluate Lua expression before processing input", {})
181✔
23
   cliargs:option("-E, --evaluate-after=VALUE", "evaluate Lua expression after processing input", {})
181✔
24
   cliargs:option("-f, --fontmanager=VALUE", "choose an alternative font manager")
181✔
25
   cliargs:option("-I, --include=FILE", "deprecated, see --use, --preamble, or --postamble", {})
181✔
26
   cliargs:option("-m, --makedeps=FILE", "generate a list of dependencies in Makefile format")
181✔
27
   cliargs:option("-o, --output=FILE", "explicitly set output file name")
181✔
28
   cliargs:option("-O, --options=PARAMETER=VALUE[,PARAMETER=VALUE]", "set document class options", {})
181✔
29
   cliargs:option("-p, --preamble=FILE", "process SIL, XML, or other content before the input document", {})
181✔
30
   cliargs:option("-P, --postamble=FILE", "process SIL, XML, or other content after the input document", {})
181✔
31
   cliargs:option(
362✔
32
      "-u, --use=MODULE[[PARAMETER=VALUE][,PARAMETER=VALUE]]",
181✔
33
      "load and initialize a module before processing input",
181✔
34
      {}
35
   )
36
   cliargs:flag("-q, --quiet", "suppress warnings and informational messages during processing")
181✔
37
   cliargs:flag("-t, --traceback", "display detailed location trace on errors and warnings")
181✔
38
   cliargs:flag("-h, --help", "display this help, then exit")
181✔
39
   cliargs:flag("-v, --version", "display version information, then exit", print_version)
181✔
40
   -- Work around cliargs not processing - as an alias for STDIO streams:
41
   -- https://github.com/amireh/lua_cliargs/issues/67
42
   local _arg = pl.tablex.imap(luautf8.gsub, _G.arg, "^-$", "STDIO")
362✔
43
   local opts, parse_err = cliargs:parse(_arg)
181✔
44
   if not opts and parse_err then
181✔
NEW
45
      print(parse_err)
×
NEW
46
      local code = parse_err:match("^Usage:") and 0 or 1
×
NEW
47
      os.exit(code)
×
48
   end
49
   if opts.INPUTS and #opts.INPUTS > 0 then
181✔
50
      local has_input_filename = false
181✔
51
      pl.tablex.foreachi(opts.INPUTS, function (v, k)
362✔
52
         if v == "STDIO" then
181✔
NEW
53
            opts.INPUTS[k] = "-"
×
54
         elseif not has_input_filename then
181✔
55
            has_input_filename = true
181✔
56
         end
57
      end)
58
      if not has_input_filename and not opts.output then
181✔
NEW
59
         SU.error(
×
60
            "Unable to derive an output filename (perhaps because input is a STDIO stream).\n"
NEW
61
               .. "  Please use --output to set one explicitly."
×
62
         )
63
      end
64
      SILE.input.filenames = opts.INPUTS
181✔
65
   end
66
   if opts.backend then
181✔
NEW
67
      SILE.backend = opts.backend
×
68
   end
69
   if opts.class then
181✔
NEW
70
      SILE.input.class = opts.class
×
71
   end
72
   for _, flags in ipairs(opts.debug) do
362✔
73
      for _, flag in ipairs(pl.stringx.split(flags, ",")) do
724✔
74
         SILE.debugFlags[flag] = true
181✔
75
      end
76
   end
77
   for _, statement in ipairs(opts["evaluate"]) do
181✔
NEW
78
      table.insert(SILE.input.evaluates, statement)
×
79
   end
80
   for _, statement in ipairs(opts["evaluate-after"]) do
181✔
NEW
81
      table.insert(SILE.input.evaluateAfters, statement)
×
82
   end
83
   if opts.fontmanager then
181✔
84
      SILE.forceFontManager = opts.fontmanager
181✔
85
   end
86
   if opts.makedeps then
181✔
87
      SILE.makeDeps = require("core.makedeps")
181✔
88
      SILE.makeDeps.filename = opts.makedeps
181✔
89
   end
90
   if opts.output then
181✔
91
      if opts.output == "STDIO" then
181✔
NEW
92
         opts.output = "-"
×
93
      end
94
      SILE.outputFilename = opts.output
181✔
95
   end
96
   for _, option in ipairs(opts.options) do
181✔
NEW
97
      local options = SILE.parserBits.parameters:match(option)
×
NEW
98
      SILE.input.options = pl.tablex.merge(SILE.input.options, options, true)
×
99
   end
100
   for _, use in ipairs(opts.use) do
181✔
NEW
101
      local spec = SILE.parserBits.cliuse:match(use)
×
NEW
102
      table.insert(SILE.input.uses, spec)
×
103
   end
104
   for _, path in ipairs(opts.preamble) do
181✔
NEW
105
      table.insert(SILE.input.preambles, path)
×
106
   end
107
   for _, path in ipairs(opts.postamble) do
181✔
NEW
108
      table.insert(SILE.input.postambles, path)
×
109
   end
110
   for _, path in ipairs(opts.include) do
181✔
NEW
111
      SU.deprecated("-I/--include", "-u/--use or -p/--preamble", "0.14.0", "0.15.0")
×
NEW
112
      table.insert(SILE.input.includes, path)
×
113
   end
114
   -- http://lua-users.org/wiki/VarargTheSecondClassCitizen
115
   local summary = function (...)
NEW
116
      local contentloc = SILE.traceStack:locationHead()
×
NEW
117
      local codeloc = pl.utils.unpack({ ... }, 1, select("#", ...))
×
NEW
118
      return ("Processing at: %s\n\tUsing code at: %s"):format(contentloc, codeloc)
×
119
   end
120
   local unexpected = function ()
NEW
121
      if not SILE.scratch.caughterror then
×
NEW
122
         io.stderr:write("\n! Unexpected Lua error\n")
×
123
      end
124
   end
125
   local trace = function (...)
NEW
126
      unexpected()
×
NEW
127
      io.stderr:write(debug.traceback("", 2) or "\t! debug.traceback() did not identify code location")
×
NEW
128
      io.stderr:write("\n")
×
NEW
129
      return summary(...)
×
130
   end
131
   local identity = function (...)
NEW
132
      unexpected()
×
NEW
133
      return summary(...) .. "\n\nRun with --traceback for more detailed trace leading up to errors."
×
134
   end
135
   SILE.errorHandler = opts.traceback and trace or identity
181✔
136
   SILE.quiet = opts.quiet
181✔
137
   SILE.traceback = opts.traceback
181✔
138
end
139

140
return cli
181✔
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