Compare commits
No commits in common. "194ab5e1f97f5051d2f372d6f41a86928750bab3" and "b94a21cb2edd6a3b5bf323e2ece748b822798932" have entirely different histories.
194ab5e1f9
...
b94a21cb2e
|
@ -55,7 +55,7 @@ Where:
|
|||
### Flags
|
||||
|
||||
* `-1`, `--first-only`: Return only the first match
|
||||
* `-e`, `--errors`: print warnings
|
||||
* `-q`, `--quiet`: Don't print warnings
|
||||
* `-t`, `--text`: Print only the [innerText](https://developer.mozilla.org/fr/docs/Web/API/HTMLElement/innerText) of the matched elements
|
||||
|
||||
## Motivation
|
||||
|
|
18
main.lua
18
main.lua
|
@ -22,7 +22,7 @@ local function print_usage()
|
|||
logger.print()
|
||||
logger.print(" Flags:")
|
||||
logger.print(" -1, --first-only: return only the first match")
|
||||
logger.print(" -e, --errors: print warnings")
|
||||
logger.print(" -q, --quiet: Don't print warnings")
|
||||
logger.print(" -t, --text: Print only the innerText of the matched elements")
|
||||
os.exit(1)
|
||||
end
|
||||
|
@ -54,7 +54,7 @@ local SHORTHAND_FLAGS = {
|
|||
if #arg < 2 then
|
||||
logger.printerr("Error: Not enough arguments")
|
||||
print_usage()
|
||||
os.exit(1)
|
||||
return 1
|
||||
end
|
||||
|
||||
local flags = {}
|
||||
|
@ -66,7 +66,7 @@ for _, argument in ipairs(arg) do
|
|||
if not SHORTHAND_FLAGS[letter] then
|
||||
logger.printerr("Unknown flag: -"..letter..".")
|
||||
print_usage()
|
||||
os.exit(1)
|
||||
return 1
|
||||
end
|
||||
|
||||
local flag = SHORTHAND_FLAGS[letter]
|
||||
|
@ -82,7 +82,7 @@ for _, argument in ipairs(arg) do
|
|||
if not LONGHAND_FLAGS[flagname] then
|
||||
logger.printerr("Unknown flag: --"..flagname..".")
|
||||
print_usage()
|
||||
os.exit(1)
|
||||
return 1
|
||||
end
|
||||
|
||||
local flag = LONGHAND_FLAGS[flagname]
|
||||
|
@ -106,7 +106,7 @@ end
|
|||
if #positionals > 2 then
|
||||
logger.printerr("Error: too many arguments !")
|
||||
print_usage()
|
||||
os.exit(1)
|
||||
return 1
|
||||
end
|
||||
|
||||
local html_file = positionals[1]
|
||||
|
@ -115,13 +115,13 @@ local html = nil
|
|||
if html_file ~= "-" then
|
||||
if not( file_exists( html_file )) then
|
||||
logger.printerr("File doesn't exist: " .. html_file)
|
||||
os.exit(2)
|
||||
return 2
|
||||
end
|
||||
|
||||
local handle = io.open( html_file, "r" )
|
||||
if not handle then
|
||||
logger.printerr("Failed to open file " .. html_file)
|
||||
os.exit(2)
|
||||
return 2
|
||||
end
|
||||
|
||||
html = handle:read("a")
|
||||
|
@ -217,13 +217,13 @@ if flags[FLAGS.FIRST_ONLY] then
|
|||
|
||||
if flags[FLAGS.INNER_TEXT] then
|
||||
logger.print( elements[1]:inner_text() )
|
||||
os.exit(0)
|
||||
return 0
|
||||
end
|
||||
|
||||
logger.print( HTML.tostring( elements[1] ) )
|
||||
end
|
||||
|
||||
os.exit(0)
|
||||
return 0
|
||||
end
|
||||
|
||||
for _, el in ipairs(elements) do
|
||||
|
|
Loading…
Reference in New Issue