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

sile-typesetter / sile / 6713098919

31 Oct 2023 10:21PM UTC coverage: 52.831% (-21.8%) from 74.636%
6713098919

push

github

web-flow
Merge d0a2a1ee9 into b185d4972

45 of 45 new or added lines in 3 files covered. (100.0%)

8173 of 15470 relevant lines covered (52.83%)

6562.28 hits per line

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

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

152
return cli
346✔
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