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

sile-typesetter / sile / 5017842917

pending completion
5017842917

push

github

GitHub
Merge pull request #1738 from alerque/multi-inputs

16 of 16 new or added lines in 2 files covered. (100.0%)

9954 of 15641 relevant lines covered (63.64%)

6575.94 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()
171✔
2

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

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