-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathampache-handshake-print.lua
63 lines (55 loc) · 2.48 KB
/
ampache-handshake-print.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
-----------------------------------------------------
-- ----------------------------------------------- --
-- ▄ ▄ ▄ ▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄ ▄ ▄ --
-- ▐░▌ ▐░▌ ▐░▌▐░█▀▀▀▀▀ ▀▀█░█▀▀ ▐░▌ ▐░▌ --
-- ▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░█ █░▌ --
-- ▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░░░░░░░▌ --
-- ▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ ▀▀▀▀▀█░▌ --
-- ▐░█▄▄▄▄▄ ▐░█▄▄▄█░▌▐░█▄▄▄▄▄ ▄▄█░█▄▄ ▐░▌ --
-- ▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀ ▀ --
-- ----------------------------------------------- --
-- -------- Helper script for handshake --------- --
-- -------- https://github.com/icefields --------- --
-----------------------------------------------------
local original_script = require("ampache-handshake")
local helpMessage = "Usage: lua ampache-handshake-print.lua [-h | --handshake | -a | --auth] <server.url> <username> <password>"
-- Check the number of command-line arguments
if #arg < 3 then
error(helpMessage)
end
local OPTION_DEFAULT = "-H"
local validOptions = {
["-H"] = false,
["--handshake"] = false,
["-a"] = false,
["--auth"] = false,
["-h"] = false,
["--help"] = false
}
local isAnyOption = false
local values = { }
for i, currArg in ipairs(arg) do
if currArg:sub(1, 1) == "-" and validOptions[currArg] ~= nil then
validOptions[currArg] = true
isAnyOption = true
else
table.insert(values, currArg)
end
end
if not isAnyOption then validOptions[OPTION_DEFAULT] = true end
local server_url = values[1]
local username = values[2]
local password = values[3]
if validOptions[OPTION_DEFAULT] or validOptions["--handshake"] then
-- Call handshake and print JSON elements line by line
local jsonResp = original_script.handshake(server_url, username, password)
for key, value in pairs(jsonResp) do
print(key .. ":", value)
end
elseif validOptions["-a"] or validOptions["--auth"] then
-- Call getAuthToken and print authentication token
local auth_token = original_script.getAuthToken(server_url, username, password)
print(auth_token)
elseif validOptions["-h"] or validOptions["--help"] then
print(helpMessage)
end