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

sile-typesetter / sile / 9304049654

30 May 2024 02:12PM UTC coverage: 60.021% (-14.7%) from 74.707%
9304049654

push

github

web-flow
Merge 1a26b4f22 into a1fd105f8

6743 of 12900 new or added lines in 186 files covered. (52.27%)

347 existing lines in 49 files now uncovered.

10311 of 17179 relevant lines covered (60.02%)

3307.34 hits per line

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

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

3
cli.parseArguments = function ()
NEW
4
   local cliargs = require("cliargs")
×
5
   local print_version = function (flag)
NEW
6
      print(flag == "V" and "SILE " .. SILE.version or SILE.full_version)
×
NEW
7
      os.exit(0)
×
8
   end
NEW
9
   cliargs:set_colsz(0, 120)
×
NEW
10
   cliargs:set_name("sile")
×
NEW
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.
UNCOV
17
    ]])
×
NEW
18
   cliargs:splat("INPUTS", "Input document filename(s), by default in SIL, XML, or Lua formats.", nil, 999)
×
NEW
19
   cliargs:option("-b, --backend=VALUE", "Specify the output backend")
×
NEW
20
   cliargs:option("-c, --class=VALUE", "Override the default or specified document class")
×
NEW
21
   cliargs:option("-d, --debug=VALUE", "Show debug information for tagged aspects of SILE’s operation", {})
×
NEW
22
   cliargs:option("-e, --evaluate=VALUE", "Evaluate Lua expression before processing input", {})
×
NEW
23
   cliargs:option("-E, --evaluate-after=VALUE", "Evaluate Lua expression after processing input", {})
×
NEW
24
   cliargs:option("-f, --fontmanager=VALUE", "Specify which font manager to use")
×
NEW
25
   cliargs:option("-I, --include=FILE", "Deprecated, see --use, --preamble, --postamble, or multiple input files", {})
×
NEW
26
   cliargs:option("-m, --makedeps=FILE", "Generate a Makefile format list of dependencies and white them to a file")
×
NEW
27
   cliargs:option("-o, --output=FILE", "Explicitly set output file name")
×
NEW
28
   cliargs:option("-O, --options=PARAMETER=VALUE[,PARAMETER=VALUE]", "Set or override document class options", {})
×
NEW
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
   )
NEW
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
   )
NEW
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
   )
NEW
44
   cliargs:flag("-q, --quiet", "Suppress warnings and informational messages during processing")
×
NEW
45
   cliargs:flag("-t, --traceback", "Display detailed location trace on errors and warnings")
×
NEW
46
   cliargs:flag("-h, --help", "Display this help, then exit")
×
NEW
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
NEW
50
   local _arg = pl.tablex.imap(luautf8.gsub, _G.arg, "^-$", "STDIO")
×
NEW
51
   local opts, parse_err = cliargs:parse(_arg)
×
NEW
52
   if not opts and parse_err then
×
NEW
53
      print(parse_err)
×
NEW
54
      local code = parse_err:match("^Usage:") and 0 or 1
×
NEW
55
      os.exit(code)
×
56
   end
NEW
57
   if opts.INPUTS and #opts.INPUTS > 0 then
×
NEW
58
      local has_input_filename = false
×
NEW
59
      pl.tablex.foreachi(opts.INPUTS, function (v, k)
×
NEW
60
         if v == "STDIO" then
×
NEW
61
            opts.INPUTS[k] = "-"
×
NEW
62
         elseif not has_input_filename then
×
NEW
63
            has_input_filename = true
×
64
         end
65
      end)
NEW
66
      if not has_input_filename and not opts.output then
×
NEW
67
         SU.error(
×
68
            "Unable to derive an output filename (perhaps because input is a STDIO stream).\n"
NEW
69
               .. "  Please use --output to set one explicitly."
×
70
         )
71
      end
NEW
72
      SILE.input.filenames = opts.INPUTS
×
73
   end
NEW
74
   if opts.backend then
×
NEW
75
      SILE.backend = opts.backend
×
76
   end
NEW
77
   if opts.class then
×
NEW
78
      SILE.input.class = opts.class
×
79
   end
NEW
80
   for _, flags in ipairs(opts.debug) do
×
NEW
81
      for _, flag in ipairs(pl.stringx.split(flags, ",")) do
×
NEW
82
         SILE.debugFlags[flag] = true
×
83
      end
84
   end
NEW
85
   for _, statement in ipairs(opts["evaluate"]) do
×
NEW
86
      table.insert(SILE.input.evaluates, statement)
×
87
   end
NEW
88
   for _, statement in ipairs(opts["evaluate-after"]) do
×
NEW
89
      table.insert(SILE.input.evaluateAfters, statement)
×
90
   end
NEW
91
   if opts.fontmanager then
×
NEW
92
      SILE.forceFontManager = opts.fontmanager
×
93
   end
NEW
94
   if opts.makedeps then
×
NEW
95
      SILE.makeDeps = require("core.makedeps")
×
NEW
96
      SILE.makeDeps.filename = opts.makedeps
×
97
   end
NEW
98
   if opts.output then
×
NEW
99
      if opts.output == "STDIO" then
×
NEW
100
         opts.output = "-"
×
101
      end
NEW
102
      SILE.outputFilename = opts.output
×
103
   end
NEW
104
   for _, option in ipairs(opts.options) do
×
NEW
105
      local options = SILE.parserBits.parameters:match(option)
×
NEW
106
      SILE.input.options = pl.tablex.merge(SILE.input.options, options, true)
×
107
   end
NEW
108
   for _, use in ipairs(opts.use) do
×
NEW
109
      local spec = SILE.parserBits.cliuse:match(use)
×
NEW
110
      table.insert(SILE.input.uses, spec)
×
111
   end
NEW
112
   for _, path in ipairs(opts.preamble) do
×
NEW
113
      table.insert(SILE.input.preambles, path)
×
114
   end
NEW
115
   for _, path in ipairs(opts.postamble) do
×
NEW
116
      table.insert(SILE.input.postambles, path)
×
117
   end
NEW
118
   if #opts.include > 0 then
×
NEW
119
      SU.deprecated("-I/--include", "-u/--use or -p/--preamble", "0.14.0", "0.15.0")
×
120
   end
121
   -- http://lua-users.org/wiki/VarargTheSecondClassCitizen
122
   local summary = function (...)
NEW
123
      local contentloc = SILE.traceStack:locationHead()
×
NEW
124
      local codeloc = pl.utils.unpack({ ... }, 1, select("#", ...))
×
NEW
125
      return ("Processing at: %s\n\tUsing code at: %s"):format(contentloc, codeloc)
×
126
   end
127
   local unexpected = function ()
NEW
128
      if not SILE.scratch.caughterror then
×
NEW
129
         io.stderr:write("\n! Unexpected Lua error\n")
×
130
      end
131
   end
132
   local trace = function (...)
NEW
133
      unexpected()
×
NEW
134
      io.stderr:write(debug.traceback("", 2) or "\t! debug.traceback() did not identify code location")
×
NEW
135
      io.stderr:write("\n")
×
NEW
136
      return summary(...)
×
137
   end
138
   local identity = function (...)
NEW
139
      unexpected()
×
NEW
140
      return summary(...) .. "\n\nRun with --traceback for more detailed trace leading up to errors."
×
141
   end
NEW
142
   SILE.errorHandler = opts.traceback and trace or identity
×
NEW
143
   SILE.quiet = opts.quiet
×
NEW
144
   SILE.traceback = opts.traceback
×
145
end
146

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