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

sile-typesetter / sile / 6156917500

12 Sep 2023 08:31AM UTC coverage: 73.771% (-0.5%) from 74.308%
6156917500

push

github

web-flow
Merge pull request #1762 from alerque/riir

2 of 2 new or added lines in 1 file covered. (100.0%)

11616 of 15746 relevant lines covered (73.77%)

6998.71 hits per line

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

2.2
/core/cli.lua
1
local cli = pl.class()
343✔
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 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
    ]])
×
18
  cliargs:splat("INPUTS", "input document(s), by default in SIL or XML format", nil, 999)
×
19
  cliargs:option("-b, --backend=VALUE", "choose an alternative output backend")
×
20
  cliargs:option("-c, --class=VALUE", "override default 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", "choose an alternative font manager")
×
25
  cliargs:option("-I, --include=FILE", "deprecated, see --use, --preamble, or --postamble", {})
×
26
  cliargs:option("-m, --makedeps=FILE", "generate a list of dependencies in Makefile format")
×
27
  cliargs:option("-o, --output=FILE", "explicitly set output file name")
×
28
  cliargs:option("-O, --options=PARAMETER=VALUE[,PARAMETER=VALUE]", "set document class options", {})
×
29
  cliargs:option("-p, --preamble=FILE", "process SIL, XML, or other content before the input document", {})
×
30
  cliargs:option("-P, --postamble=FILE", "process SIL, XML, or other content after the input document", {})
×
31
  cliargs:option("-u, --use=MODULE[[PARAMETER=VALUE][,PARAMETER=VALUE]]", "load and initialize a module before processing input", {})
×
32
  cliargs:flag("-q, --quiet", "suppress warnings and informational messages during processing")
×
33
  cliargs:flag("-t, --traceback", "display detailed location trace on errors and warnings")
×
34
  cliargs:flag("-h, --help", "display this help, then exit")
×
35
  cliargs:flag("-V, --version", "display version information, then exit", print_version)
×
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")
×
39
  local opts, parse_err = cliargs:parse(_arg)
×
40
  if not opts and parse_err then
×
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
×
46
    local has_input_filename = false
×
47
    pl.tablex.foreachi(opts.INPUTS, function (v, k)
×
48
      if v == "STDIO" then
×
49
        opts.INPUTS[k] = "-"
×
50
      elseif not has_input_filename then
×
51
        has_input_filename = true
×
52
      end
53
    end)
54
    if not has_input_filename and not opts.output then
×
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
×
59
  end
60
  if opts.backend then
×
61
    SILE.backend = opts.backend
×
62
  end
63
  if opts.class then
×
64
    SILE.input.class = opts.class
×
65
  end
66
  for _, flags in ipairs(opts.debug) do
×
67
    for _, flag in ipairs(pl.stringx.split(flags, ",")) do
×
68
      SILE.debugFlags[flag] = true
×
69
    end
70
  end
71
  for _, statement in ipairs(opts["evaluate"]) do
×
72
    table.insert(SILE.input.evaluates, statement)
×
73
  end
74
  for _, statement in ipairs(opts["evaluate-after"]) do
×
75
    table.insert(SILE.input.evaluateAfters, statement)
×
76
  end
77
  if opts.fontmanager then
×
78
    SILE.forceFontManager = opts.fontmanager
×
79
  end
80
  if opts.makedeps then
×
81
    SILE.makeDeps = require("core.makedeps")
×
82
    SILE.makeDeps.filename = opts.makedeps
×
83
  end
84
  if opts.output then
×
85
    if opts.output == "STDIO" then
×
86
      opts.output = "-"
×
87
    end
88
    SILE.outputFilename = opts.output
×
89
  end
90
  for _, option in ipairs(opts.options) do
×
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
×
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
×
99
    table.insert(SILE.input.preambles, path)
×
100
  end
101
  for _, path in ipairs(opts.postamble) do
×
102
    table.insert(SILE.input.postambles, path)
×
103
  end
104
  for _, path in ipairs(opts.include) do
×
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()
×
111
    local codeloc = table.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
×
130
  SILE.quiet = opts.quiet
×
131
  SILE.traceback = opts.traceback
×
132
end
133

134
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

© 2026 Coveralls, Inc