Skip to content

Commit 12aafd7

Browse files
committed
CL: Added --help option.
1 parent da39da8 commit 12aafd7

File tree

1 file changed

+122
-118
lines changed

1 file changed

+122
-118
lines changed

preprocess-cl.lua

Lines changed: 122 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
_=[[
33
exec lua "$0" "$@"
44
]]
5-
--[[============================================================
5+
--==============================================================
66
--=
77
--= LuaPreprocess command line program
88
--= by Marcus 'ReFreezed' Thunström
@@ -16,117 +16,118 @@ exec lua "$0" "$@"
1616
--= Tested with Lua 5.1, 5.2, 5.3, 5.4 and LuaJIT.
1717
--=
1818
--==============================================================
19-
20-
Script usage:
21-
lua preprocess-cl.lua [options] [--] filepath1 [filepath2 ...]
22-
OR
23-
lua preprocess-cl.lua --outputpaths [options] [--] inputpath1 outputpath1 [inputpath2 outputpath2 ...]
24-
25-
File paths can be "-" for usage of stdin/stdout.
26-
27-
Examples:
28-
lua preprocess-cl.lua --saveinfo=logs/info.lua --silent src/main.lua2p src/network.lua2p
29-
lua preprocess-cl.lua --debug src/main.lua2p src/network.lua2p
30-
lua preprocess-cl.lua --outputpaths --linenumbers src/main.lua2p output/main.lua src/network.lua2p output/network.lua
31-
32-
Options:
33-
--backtickstrings
34-
Enable the backtick (`) to be used as string literal delimiters.
35-
Backtick strings don't interpret any escape sequences and can't
36-
contain other backticks.
37-
38-
--data|-d="Any data."
39-
A string with any data. If this option is present then the value
40-
will be available through the global 'dataFromCommandLine' in the
41-
processed files (and any message handler). Otherwise,
42-
'dataFromCommandLine' is nil.
43-
44-
--faststrings
45-
Force fast serialization of string values. (Non-ASCII characters
46-
will look ugly.)
47-
48-
--handler|-h=pathToMessageHandler
49-
Path to a Lua file that's expected to return a function or a
50-
table of functions. If it returns a function then it will be
51-
called with various messages as it's first argument. If it's
52-
a table, the keys should be the message names and the values
53-
should be functions to handle the respective message.
54-
(See 'Handler messages' and tests/quickTestHandler*.lua)
55-
The file shares the same environment as the processed files.
56-
57-
--jitsyntax
58-
Allow LuaJIT-specific syntax, specifically literals for 64-bit
59-
integers and complex numbers.
60-
(https://luajit.org/ext_ffi_api.html#literals)
61-
62-
--linenumbers
63-
Add comments with line numbers to the output.
64-
65-
--loglevel=levelName
66-
Set maximum log level for the @@LOG() macro. Can be "off",
67-
"error", "warning", "info", "debug" or "trace". The default is
68-
"trace", which enables all logging.
69-
70-
--macroprefix=prefix
71-
String to prepend to macro names.
72-
73-
--macrosuffix=suffix
74-
String to append to macro names.
75-
76-
--meta OR --meta=pathToSaveMetaprogramTo
77-
Output the metaprogram to a temporary file (*.meta.lua). Useful if
78-
an error happens when the metaprogram runs. This file is removed
79-
if there's no error and --debug isn't enabled.
80-
81-
--nogc
82-
Stop the garbage collector. This may speed up the preprocessing.
83-
84-
--nonil
85-
Disallow !(...) and outputValue(...) from outputting nil.
86-
87-
--novalidate
88-
Disable validation of outputted Lua.
89-
90-
--outputextension=fileExtension
91-
Specify what file extension generated files should have. The
92-
default is "lua". If any input files end in .lua then you must
93-
specify another file extension with this option. (It's suggested
94-
that you use .lua2p (as in "Lua To Process") as extension for
95-
unprocessed files.)
96-
97-
--outputpaths|-o
98-
This flag makes every other specified path be the output path
99-
for the previous path.
100-
101-
--release
102-
Enable release mode. Currently only disables the @@ASSERT() macro.
103-
104-
--saveinfo|-i=pathToSaveProcessingInfoTo
105-
Processing information includes what files had any preprocessor
106-
code in them, and things like that. The format of the file is a
107-
lua module that returns a table. Search this file for 'SavedInfo'
108-
to see what information is saved.
109-
110-
--silent
111-
Only print errors to the console. (This flag is automatically
112-
enabled if an output path is stdout.)
113-
114-
--version
115-
Print the version of LuaPreprocess to stdout and exit.
116-
117-
--debug
118-
Enable some preprocessing debug features. Useful if you want
119-
to inspect the generated metaprogram (*.meta.lua). (This also
120-
enables the --meta option.)
121-
122-
--
123-
Stop options from being parsed further. Needed if you have paths
124-
starting with "-" (except for usage of stdin/stdout).
125-
126-
----------------------------------------------------------------
127-
128-
Handler messages:
129-
19+
local help = [[
20+
21+
Script usage:
22+
lua preprocess-cl.lua [options] [--] filepath1 [filepath2 ...]
23+
OR
24+
lua preprocess-cl.lua --outputpaths [options] [--] inputpath1 outputpath1 [inputpath2 outputpath2 ...]
25+
26+
File paths can be "-" for usage of stdin/stdout.
27+
28+
Examples:
29+
lua preprocess-cl.lua --saveinfo=logs/info.lua --silent src/main.lua2p src/network.lua2p
30+
lua preprocess-cl.lua --debug src/main.lua2p src/network.lua2p
31+
lua preprocess-cl.lua --outputpaths --linenumbers src/main.lua2p output/main.lua src/network.lua2p output/network.lua
32+
33+
Options:
34+
--backtickstrings
35+
Enable the backtick (`) to be used as string literal delimiters.
36+
Backtick strings don't interpret any escape sequences and can't
37+
contain other backticks.
38+
39+
--data|-d="Any data."
40+
A string with any data. If this option is present then the value
41+
will be available through the global 'dataFromCommandLine' in the
42+
processed files (and any message handler). Otherwise,
43+
'dataFromCommandLine' is nil.
44+
45+
--faststrings
46+
Force fast serialization of string values. (Non-ASCII characters
47+
will look ugly.)
48+
49+
--handler|-h=pathToMessageHandler
50+
Path to a Lua file that's expected to return a function or a
51+
table of functions. If it returns a function then it will be
52+
called with various messages as it's first argument. If it's
53+
a table, the keys should be the message names and the values
54+
should be functions to handle the respective message.
55+
(See 'Handler messages' and tests/quickTestHandler*.lua)
56+
The file shares the same environment as the processed files.
57+
58+
--help
59+
Show this help.
60+
61+
--jitsyntax
62+
Allow LuaJIT-specific syntax, specifically literals for 64-bit
63+
integers and complex numbers.
64+
(https://luajit.org/ext_ffi_api.html#literals)
65+
66+
--linenumbers
67+
Add comments with line numbers to the output.
68+
69+
--loglevel=levelName
70+
Set maximum log level for the @@LOG() macro. Can be "off",
71+
"error", "warning", "info", "debug" or "trace". The default is
72+
"trace", which enables all logging.
73+
74+
--macroprefix=prefix
75+
String to prepend to macro names.
76+
77+
--macrosuffix=suffix
78+
String to append to macro names.
79+
80+
--meta OR --meta=pathToSaveMetaprogramTo
81+
Output the metaprogram to a temporary file (*.meta.lua). Useful if
82+
an error happens when the metaprogram runs. This file is removed
83+
if there's no error and --debug isn't enabled.
84+
85+
--nogc
86+
Stop the garbage collector. This may speed up the preprocessing.
87+
88+
--nonil
89+
Disallow !(...) and outputValue(...) from outputting nil.
90+
91+
--novalidate
92+
Disable validation of outputted Lua.
93+
94+
--outputextension=fileExtension
95+
Specify what file extension generated files should have. The
96+
default is "lua". If any input files end in .lua then you must
97+
specify another file extension with this option. (It's suggested
98+
that you use .lua2p (as in "Lua To Process") as extension for
99+
unprocessed files.)
100+
101+
--outputpaths|-o
102+
This flag makes every other specified path be the output path
103+
for the previous path.
104+
105+
--release
106+
Enable release mode. Currently only disables the @@ASSERT() macro.
107+
108+
--saveinfo|-i=pathToSaveProcessingInfoTo
109+
Processing information includes what files had any preprocessor
110+
code in them, and things like that. The format of the file is a
111+
lua module that returns a table. Search this file for 'SavedInfo'
112+
to see what information is saved.
113+
114+
--silent
115+
Only print errors to the console. (This flag is automatically
116+
enabled if an output path is stdout.)
117+
118+
--version
119+
Print the version of LuaPreprocess to stdout and exit.
120+
121+
--debug
122+
Enable some preprocessing debug features. Useful if you want
123+
to inspect the generated metaprogram (*.meta.lua). (This also
124+
enables the --meta option.)
125+
126+
--
127+
Stop options from being parsed further. Needed if you have paths
128+
starting with "-" (except for usage of stdin/stdout).
129+
130+
Handler messages:
130131
"init"
131132
Sent before any other message.
132133
Arguments:
@@ -167,8 +168,10 @@ exec lua "$0" "$@"
167168
Sent after all other messages (right before the program exits).
168169
Arguments:
169170
(none)
171+
]]
172+
--==============================================================
173+
170174

171-
--============================================================]]
172175

173176
local startTime = os.time()
174177
local startClock = os.clock()
@@ -291,7 +294,12 @@ local pathsIn = {}
291294
local pathsOut = {}
292295

293296
for _, arg in ipairs(args) do
294-
if not (processOptions and arg:find"^%-.") then
297+
if processOptions and (arg:find"^%-%-?help$" or arg == "/?" or arg:find"^/[Hh][Ee][Ll][Pp]$") then
298+
print("LuaPreprocess v"..pp.VERSION)
299+
print((help:gsub("\t", " ")))
300+
os.exit()
301+
302+
elseif not (processOptions and arg:find"^%-.") then
295303
local paths = (hasOutputPaths and #pathsOut < #pathsIn) and pathsOut or pathsIn
296304
table.insert(paths, arg)
297305

@@ -375,10 +383,6 @@ for _, arg in ipairs(args) do
375383
io.stdout:write(pp.VERSION)
376384
os.exit()
377385

378-
-- elseif arg == "/?" or arg:find"^%-%-?help" or arg:lower() == "/help" then
379-
-- -- @Incomplete!
380-
-- os.exit()
381-
382386
else
383387
errorLine("Unknown option '"..arg:gsub("=.*", "").."'.")
384388
end

0 commit comments

Comments
 (0)