From 1db8bf3119a9a60fba9225a17bd15405f826ea5b Mon Sep 17 00:00:00 2001 From: Wouter R Date: Thu, 25 Feb 2016 23:39:23 +0100 Subject: [PATCH] Accept second command-line argument as filter set name. Fixes #55. --- src/script/loglite.lua | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/script/loglite.lua b/src/script/loglite.lua index 0d295c5..30611fc 100644 --- a/src/script/loglite.lua +++ b/src/script/loglite.lua @@ -201,16 +201,21 @@ local function readConfigFile(filename, searchPath) return dofile(fullPath) end +--NOTE: if command-line options get any more complex, switch to a lightweight +-- getopt like this one? https://attractivechaos.wordpress.com/2011/04/07/getopt-for-lua/ local function main() if #arg > 0 and arg[1] == "-h" or arg[1] == "--help" then - print("Usage: either pass file to tail as argument, or pipe through stdin.") + print("Usage: loglite.lua [file-to-tail] [filter-set]") + print(" If no arguments are supplied, or if the first one is `-', stdin is used as input.") + print(" If no filter set is supplied, a set named `default' will be looked for.") + print(" Filter sets can be defined in a file `loglite-filters.lua' in your home directory.") os.exit(0) end - local followFile = #arg > 0 and arg[1] or nil - local filterSetName = 'default' -- TODO: parse from options and leave at 'default' if not specified + local followFile = #arg > 0 and arg[1] ~= '-' and arg[1] or nil + local filterSetName = #arg > 1 and arg[2] or 'default' - --print("[DEBUG] following file: '" .. (followFile and followFile or "") .. "'.") + --print("[DEBUG] following file: '" .. (followFile and followFile or "") .. "', with filter set '" .. filterSetName .. "'.") --local tailin = io.popen('tail -F '..(...)..' 2>&1', 'r')