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

sile-typesetter / sile / 6876872636

15 Nov 2023 11:50AM UTC coverage: 68.751% (+6.5%) from 62.266%
6876872636

Pull #1904

github

web-flow
Merge pull request #1908 from alerque/reload-package
Pull Request #1904: Merge develop into master (commit to next release being breaking)

44 of 103 new or added lines in 14 files covered. (42.72%)

191 existing lines in 7 files now uncovered.

10699 of 15562 relevant lines covered (68.75%)

6786.21 hits per line

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

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

151
return cli
343✔
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