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

sile-typesetter / sile / 11135083927

01 Oct 2024 11:26PM UTC coverage: 62.071% (-7.3%) from 69.333%
11135083927

push

github

alerque
style: Reformat Lua with stylua

0 of 9 new or added lines in 2 files covered. (0.0%)

1678 existing lines in 57 files now uncovered.

11071 of 17836 relevant lines covered (62.07%)

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

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

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