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

sile-typesetter / sile / 3849002768

pending completion
3849002768

push

github

GitHub
Merge f1334c9ed into 13df3c1f5

53 of 53 new or added lines in 7 files covered. (100.0%)

11 of 14758 relevant lines covered (0.07%)

0.0 hits per line

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

0.0
/core/cli.lua
1
local cli = pl.class()
×
2

3
cli.parseArguments = function ()
4
  local cliargs = require("cliargs")
×
5
  local print_version = function()
6
    print(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("INPUT", "input document, by default in SIL or XML format")
×
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("-t, --traceback", "display detailed location trace on errors and warnings")
×
33
  cliargs:flag("-h, --help", "display this help, then exit")
×
34
  cliargs:flag("-v, --version", "display version information, then exit", print_version)
×
35
  -- Work around cliargs not processing - as an alias for STDIO streams:
36
  -- https://github.com/amireh/lua_cliargs/issues/67
37
  local _arg = pl.tablex.imap(luautf8.gsub, _G.arg, "^-$", "STDIO")
×
38
  local opts, parse_err = cliargs:parse(_arg)
×
39
  if not opts and parse_err then
×
40
    print(parse_err)
×
41
    os.exit(1)
×
42
  end
43
  if opts.INPUT then
×
44
    if opts.INPUT == "STDIO" then
×
45
      opts.INPUT = "-"
×
46
    end
47
    SILE.input.filename = opts.INPUT
×
48
    -- Turn slashes around in the event we get passed a path from a Windows shell
49
    local filename = opts.INPUT:gsub("\\", "/")
×
50
    -- Strip extension
51
    SILE.masterFilename = string.match(filename, "(.+)%..-$") or filename
×
52
    SILE.masterDir = SILE.masterFilename:match("(.-)[^%/]+$")
×
53
  end
54
  if opts.backend then
×
55
    SILE.backend = opts.backend
×
56
  end
57
  if opts.class then
×
58
    SILE.input.class = opts.class
×
59
  end
60
  for _, flags in ipairs(opts.debug) do
×
61
    for _, flag in ipairs(pl.stringx.split(flags, ",")) do
×
62
      SILE.debugFlags[flag] = true
×
63
    end
64
  end
65
  for _, statement in ipairs(opts["evaluate"]) do
×
66
    table.insert(SILE.input.evaluates, statement)
×
67
  end
68
  for _, statement in ipairs(opts["evaluate-after"]) do
×
69
    table.insert(SILE.input.evaluateAfters, statement)
×
70
  end
71
  if opts.fontmanager then
×
72
    SILE.forceFontManager = opts.fontmanager
×
73
  end
74
  if opts.makedeps then
×
75
    SILE.makeDeps = require("core.makedeps")
×
76
    SILE.makeDeps.filename = opts.makedeps
×
77
  end
78
  if opts.output then
×
79
    if opts.output == "STDIO" then
×
80
      opts.output = "-"
×
81
    end
82
    SILE.outputFilename = opts.output
×
83
  end
84
  for _, option in ipairs(opts.options) do
×
85
    local options = SILE.parserBits.parameters:match(option)
×
86
    SILE.input.options = pl.tablex.merge(SILE.input.options, options, true)
×
87
  end
88
  for _, use in ipairs(opts.use) do
×
89
    local spec = SILE.parserBits.cliuse:match(use)
×
90
    table.insert(SILE.input.uses, spec)
×
91
  end
92
  for _, path in ipairs(opts.preamble) do
×
93
    table.insert(SILE.input.preambles, path)
×
94
  end
95
  for _, path in ipairs(opts.postamble) do
×
96
    table.insert(SILE.input.postambles, path)
×
97
  end
98
  for _, path in ipairs(opts.include) do
×
99
    SU.deprecated("-I/--include", "-u/--use or -p/--preamble", "0.14.0", "0.15.0")
×
100
    table.insert(SILE.input.includes, path)
×
101
  end
102
  -- http://lua-users.org/wiki/VarargTheSecondClassCitizen
103
  local summary = function (...)
104
    local contentloc = SILE.traceStack:locationHead()
×
105
    local codeloc = table.unpack({...}, 1, select('#', ...))
×
106
    return ("Processing at: %s\n\tUsing code at: %s"):format(contentloc, codeloc)
×
107
  end
108
  local unexpected = function ()
109
    if not SILE.scratch.caughterror then
×
110
      io.stderr:write("\n! Unexpected Lua error\n")
×
111
    end
112
  end
113
  local trace = function (...)
114
    unexpected()
×
115
    io.stderr:write(debug.traceback("", 2) or "\t! debug.traceback() did not identify code location")
×
116
    io.stderr:write("\n")
×
117
    return summary(...)
×
118
  end
119
  local identity = function (...)
120
    unexpected()
×
121
    return summary(...) .. "\n\nRun with --traceback for more detailed trace leading up to errors."
×
122
  end
123
  SILE.errorHandler = opts.traceback and trace or identity
×
124
  SILE.traceback = opts.traceback
×
125
end
126

127
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

© 2026 Coveralls, Inc