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

sile-typesetter / sile / 9400953783

06 Jun 2024 12:32PM UTC coverage: 62.819% (-11.3%) from 74.124%
9400953783

push

github

alerque
Merge branch 'develop'

1752 of 2644 new or added lines in 109 files covered. (66.26%)

2019 existing lines in 84 files now uncovered.

10830 of 17240 relevant lines covered (62.82%)

3306.33 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 ()
UNCOV
4
   local cliargs = require("cliargs")
×
5
   local print_version = function (flag)
NEW
6
      print(flag == "V" and "SILE " .. SILE.version or SILE.full_version)
×
UNCOV
7
      os.exit(0)
×
8
   end
UNCOV
9
   cliargs:set_colsz(0, 120)
×
UNCOV
10
   cliargs:set_name("sile")
×
UNCOV
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
   )
UNCOV
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
UNCOV
50
   local _arg = pl.tablex.imap(luautf8.gsub, _G.arg, "^-$", "STDIO")
×
UNCOV
51
   local opts, parse_err = cliargs:parse(_arg)
×
UNCOV
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
UNCOV
57
   if opts.INPUTS and #opts.INPUTS > 0 then
×
UNCOV
58
      local has_input_filename = false
×
UNCOV
59
      pl.tablex.foreachi(opts.INPUTS, function (v, k)
×
UNCOV
60
         if v == "STDIO" then
×
61
            opts.INPUTS[k] = "-"
×
UNCOV
62
         elseif not has_input_filename then
×
UNCOV
63
            has_input_filename = true
×
64
         end
65
      end)
UNCOV
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).\n"
69
               .. "  Please use --output to set one explicitly."
×
70
         )
71
      end
UNCOV
72
      SILE.input.filenames = opts.INPUTS
×
73
   end
UNCOV
74
   if opts.backend then
×
75
      SILE.backend = opts.backend
×
76
   end
UNCOV
77
   if opts.class then
×
78
      SILE.input.class = opts.class
×
79
   end
UNCOV
80
   for _, flags in ipairs(opts.debug) do
×
UNCOV
81
      for _, flag in ipairs(pl.stringx.split(flags, ",")) do
×
UNCOV
82
         SILE.debugFlags[flag] = true
×
83
      end
84
   end
UNCOV
85
   for _, statement in ipairs(opts["evaluate"]) do
×
86
      table.insert(SILE.input.evaluates, statement)
×
87
   end
UNCOV
88
   for _, statement in ipairs(opts["evaluate-after"]) do
×
89
      table.insert(SILE.input.evaluateAfters, statement)
×
90
   end
UNCOV
91
   if opts.fontmanager then
×
UNCOV
92
      SILE.forceFontManager = opts.fontmanager
×
93
   end
UNCOV
94
   if opts.makedeps then
×
UNCOV
95
      SILE.makeDeps = require("core.makedeps")
×
UNCOV
96
      SILE.makeDeps.filename = opts.makedeps
×
97
   end
UNCOV
98
   if opts.output then
×
UNCOV
99
      if opts.output == "STDIO" then
×
100
         opts.output = "-"
×
101
      end
UNCOV
102
      SILE.outputFilename = opts.output
×
103
   end
UNCOV
104
   for _, option in ipairs(opts.options) do
×
105
      local options = SILE.parserBits.parameters:match(option)
×
106
      SILE.input.options = pl.tablex.merge(SILE.input.options, options, true)
×
107
   end
UNCOV
108
   for _, use in ipairs(opts.use) do
×
109
      local spec = SILE.parserBits.cliuse:match(use)
×
110
      table.insert(SILE.input.uses, spec)
×
111
   end
UNCOV
112
   for _, path in ipairs(opts.preamble) do
×
113
      table.insert(SILE.input.preambles, path)
×
114
   end
UNCOV
115
   for _, path in ipairs(opts.postamble) do
×
116
      table.insert(SILE.input.postambles, path)
×
117
   end
NEW
118
   if #opts.include > 0 then
×
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 (...)
123
      local contentloc = SILE.traceStack:locationHead()
×
124
      local codeloc = pl.utils.unpack({ ... }, 1, select("#", ...))
×
125
      return ("Processing at: %s\n\tUsing code at: %s"):format(contentloc, codeloc)
×
126
   end
127
   local unexpected = function ()
128
      if not SILE.scratch.caughterror then
×
129
         io.stderr:write("\n! Unexpected Lua error\n")
×
130
      end
131
   end
132
   local trace = function (...)
133
      unexpected()
×
134
      io.stderr:write(debug.traceback("", 2) or "\t! debug.traceback() did not identify code location")
×
135
      io.stderr:write("\n")
×
136
      return summary(...)
×
137
   end
138
   local identity = function (...)
139
      unexpected()
×
140
      return summary(...) .. "\n\nRun with --traceback for more detailed trace leading up to errors."
×
141
   end
UNCOV
142
   SILE.errorHandler = opts.traceback and trace or identity
×
UNCOV
143
   SILE.quiet = opts.quiet
×
UNCOV
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

© 2025 Coveralls, Inc