Skip to content

Commit

Permalink
CL: Added --help option.
Browse files Browse the repository at this point in the history
  • Loading branch information
ReFreezed committed Jul 1, 2022
1 parent da39da8 commit 12aafd7
Showing 1 changed file with 122 additions and 118 deletions.
240 changes: 122 additions & 118 deletions preprocess-cl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
_=[[
exec lua "$0" "$@"
]]
--[[============================================================
--==============================================================
--=
--= LuaPreprocess command line program
--= by Marcus 'ReFreezed' Thunström
Expand All @@ -16,117 +16,118 @@ exec lua "$0" "$@"
--= Tested with Lua 5.1, 5.2, 5.3, 5.4 and LuaJIT.
--=
--==============================================================
Script usage:
lua preprocess-cl.lua [options] [--] filepath1 [filepath2 ...]
OR
lua preprocess-cl.lua --outputpaths [options] [--] inputpath1 outputpath1 [inputpath2 outputpath2 ...]
File paths can be "-" for usage of stdin/stdout.
Examples:
lua preprocess-cl.lua --saveinfo=logs/info.lua --silent src/main.lua2p src/network.lua2p
lua preprocess-cl.lua --debug src/main.lua2p src/network.lua2p
lua preprocess-cl.lua --outputpaths --linenumbers src/main.lua2p output/main.lua src/network.lua2p output/network.lua
Options:
--backtickstrings
Enable the backtick (`) to be used as string literal delimiters.
Backtick strings don't interpret any escape sequences and can't
contain other backticks.
--data|-d="Any data."
A string with any data. If this option is present then the value
will be available through the global 'dataFromCommandLine' in the
processed files (and any message handler). Otherwise,
'dataFromCommandLine' is nil.
--faststrings
Force fast serialization of string values. (Non-ASCII characters
will look ugly.)
--handler|-h=pathToMessageHandler
Path to a Lua file that's expected to return a function or a
table of functions. If it returns a function then it will be
called with various messages as it's first argument. If it's
a table, the keys should be the message names and the values
should be functions to handle the respective message.
(See 'Handler messages' and tests/quickTestHandler*.lua)
The file shares the same environment as the processed files.
--jitsyntax
Allow LuaJIT-specific syntax, specifically literals for 64-bit
integers and complex numbers.
(https://luajit.org/ext_ffi_api.html#literals)
--linenumbers
Add comments with line numbers to the output.
--loglevel=levelName
Set maximum log level for the @@LOG() macro. Can be "off",
"error", "warning", "info", "debug" or "trace". The default is
"trace", which enables all logging.
--macroprefix=prefix
String to prepend to macro names.
--macrosuffix=suffix
String to append to macro names.
--meta OR --meta=pathToSaveMetaprogramTo
Output the metaprogram to a temporary file (*.meta.lua). Useful if
an error happens when the metaprogram runs. This file is removed
if there's no error and --debug isn't enabled.
--nogc
Stop the garbage collector. This may speed up the preprocessing.
--nonil
Disallow !(...) and outputValue(...) from outputting nil.
--novalidate
Disable validation of outputted Lua.
--outputextension=fileExtension
Specify what file extension generated files should have. The
default is "lua". If any input files end in .lua then you must
specify another file extension with this option. (It's suggested
that you use .lua2p (as in "Lua To Process") as extension for
unprocessed files.)
--outputpaths|-o
This flag makes every other specified path be the output path
for the previous path.
--release
Enable release mode. Currently only disables the @@ASSERT() macro.
--saveinfo|-i=pathToSaveProcessingInfoTo
Processing information includes what files had any preprocessor
code in them, and things like that. The format of the file is a
lua module that returns a table. Search this file for 'SavedInfo'
to see what information is saved.
--silent
Only print errors to the console. (This flag is automatically
enabled if an output path is stdout.)
--version
Print the version of LuaPreprocess to stdout and exit.
--debug
Enable some preprocessing debug features. Useful if you want
to inspect the generated metaprogram (*.meta.lua). (This also
enables the --meta option.)
--
Stop options from being parsed further. Needed if you have paths
starting with "-" (except for usage of stdin/stdout).
----------------------------------------------------------------
Handler messages:
local help = [[
Script usage:
lua preprocess-cl.lua [options] [--] filepath1 [filepath2 ...]
OR
lua preprocess-cl.lua --outputpaths [options] [--] inputpath1 outputpath1 [inputpath2 outputpath2 ...]
File paths can be "-" for usage of stdin/stdout.
Examples:
lua preprocess-cl.lua --saveinfo=logs/info.lua --silent src/main.lua2p src/network.lua2p
lua preprocess-cl.lua --debug src/main.lua2p src/network.lua2p
lua preprocess-cl.lua --outputpaths --linenumbers src/main.lua2p output/main.lua src/network.lua2p output/network.lua
Options:
--backtickstrings
Enable the backtick (`) to be used as string literal delimiters.
Backtick strings don't interpret any escape sequences and can't
contain other backticks.
--data|-d="Any data."
A string with any data. If this option is present then the value
will be available through the global 'dataFromCommandLine' in the
processed files (and any message handler). Otherwise,
'dataFromCommandLine' is nil.
--faststrings
Force fast serialization of string values. (Non-ASCII characters
will look ugly.)
--handler|-h=pathToMessageHandler
Path to a Lua file that's expected to return a function or a
table of functions. If it returns a function then it will be
called with various messages as it's first argument. If it's
a table, the keys should be the message names and the values
should be functions to handle the respective message.
(See 'Handler messages' and tests/quickTestHandler*.lua)
The file shares the same environment as the processed files.
--help
Show this help.
--jitsyntax
Allow LuaJIT-specific syntax, specifically literals for 64-bit
integers and complex numbers.
(https://luajit.org/ext_ffi_api.html#literals)
--linenumbers
Add comments with line numbers to the output.
--loglevel=levelName
Set maximum log level for the @@LOG() macro. Can be "off",
"error", "warning", "info", "debug" or "trace". The default is
"trace", which enables all logging.
--macroprefix=prefix
String to prepend to macro names.
--macrosuffix=suffix
String to append to macro names.
--meta OR --meta=pathToSaveMetaprogramTo
Output the metaprogram to a temporary file (*.meta.lua). Useful if
an error happens when the metaprogram runs. This file is removed
if there's no error and --debug isn't enabled.
--nogc
Stop the garbage collector. This may speed up the preprocessing.
--nonil
Disallow !(...) and outputValue(...) from outputting nil.
--novalidate
Disable validation of outputted Lua.
--outputextension=fileExtension
Specify what file extension generated files should have. The
default is "lua". If any input files end in .lua then you must
specify another file extension with this option. (It's suggested
that you use .lua2p (as in "Lua To Process") as extension for
unprocessed files.)
--outputpaths|-o
This flag makes every other specified path be the output path
for the previous path.
--release
Enable release mode. Currently only disables the @@ASSERT() macro.
--saveinfo|-i=pathToSaveProcessingInfoTo
Processing information includes what files had any preprocessor
code in them, and things like that. The format of the file is a
lua module that returns a table. Search this file for 'SavedInfo'
to see what information is saved.
--silent
Only print errors to the console. (This flag is automatically
enabled if an output path is stdout.)
--version
Print the version of LuaPreprocess to stdout and exit.
--debug
Enable some preprocessing debug features. Useful if you want
to inspect the generated metaprogram (*.meta.lua). (This also
enables the --meta option.)
--
Stop options from being parsed further. Needed if you have paths
starting with "-" (except for usage of stdin/stdout).
Handler messages:
"init"
Sent before any other message.
Arguments:
Expand Down Expand Up @@ -167,8 +168,10 @@ exec lua "$0" "$@"
Sent after all other messages (right before the program exits).
Arguments:
(none)
]]
--==============================================================


--============================================================]]

local startTime = os.time()
local startClock = os.clock()
Expand Down Expand Up @@ -291,7 +294,12 @@ local pathsIn = {}
local pathsOut = {}

for _, arg in ipairs(args) do
if not (processOptions and arg:find"^%-.") then
if processOptions and (arg:find"^%-%-?help$" or arg == "/?" or arg:find"^/[Hh][Ee][Ll][Pp]$") then
print("LuaPreprocess v"..pp.VERSION)
print((help:gsub("\t", " ")))
os.exit()

elseif not (processOptions and arg:find"^%-.") then
local paths = (hasOutputPaths and #pathsOut < #pathsIn) and pathsOut or pathsIn
table.insert(paths, arg)

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

-- elseif arg == "/?" or arg:find"^%-%-?help" or arg:lower() == "/help" then
-- -- @Incomplete!
-- os.exit()

else
errorLine("Unknown option '"..arg:gsub("=.*", "").."'.")
end
Expand Down

0 comments on commit 12aafd7

Please sign in to comment.