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

sile-typesetter / sile / 7141747182

08 Dec 2023 01:08PM UTC coverage: 72.188% (-2.4%) from 74.636%
7141747182

push

github

web-flow
Merge pull request #1924 from alerque/lint-fixes

4 of 10 new or added lines in 8 files covered. (40.0%)

376 existing lines in 13 files now uncovered.

11384 of 15770 relevant lines covered (72.19%)

6898.07 hits per line

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

64.84
/core/cli.lua
1
local cli = pl.class()
173✔
2

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

134
return cli
173✔
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