-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathophal_cli.lua
More file actions
132 lines (108 loc) · 3.55 KB
/
Copy pathophal_cli.lua
File metadata and controls
132 lines (108 loc) · 3.55 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
local seawolf = {
contrib = require 'seawolf.contrib',
other = require 'seawolf.other',
}
local table_shift = seawolf.contrib.table_shift
local tconcat = table.concat
local m; m = {
aliases = {},
build_aliases = function()
for _, command in pairs(m.commands) do
if command.alias ~= nil then
m.aliases[command.alias] = command
end
end
end,
bootstrap = function(arg)
local cmd, output, arguments
local commands, aliases = m.commands, m.aliases
-- TODO: detect and bootstrap Ophal.
m.build_aliases()
-- Execute command
cmd = commands[arg[1]]
alias = aliases[arg[1]]
arguments = table_shift(arg)
if type(cmd) == 'table' then
output = cmd.exec(arguments)
elseif type(alias) == 'table' then
output = alias.exec(arguments)
else
output = commands.help.exec()
end
print(output)
end,
commands = {
help = {
description = 'Display help information about ophal-cli',
exec = function(arg)
local output = {
"usage: ophal <command> [<args>]\n",
"Commands:",
}
for k, v in pairs(m.commands) do
output[#output + 1] = (' %s %s'):format(k, v.description)
if v.alias then
output[#output + 1] = (' %s'):format(v.alias)
end
output[#output + 1] = ''
end
return tconcat(output, "\n")
end
},
['uuid-generate'] = {
description = 'Generate a new UUID (depends on luuid Lua module).',
alias = 'uuid',
exec = function()
local uuid = require 'uuid'
if uuid ~= nil then
return uuid.new()
else
return 'Error: Can not generate a new uuid. Please make sure to have the uuid Lua module installed in your system and try again.'
end
end
},
['sha1-hash'] = {
description = 'Generate a sha1 hash (depends on sha1 Lua module).',
alias = 'sha1',
exec = function(arg)
local sha1 = require 'sha1'
if sha1 == nil then
return 'Error: Can not generate a new sha1 hash. Please make sure to have the sha1 module installed in your system and try again.'
end
if arg[1] == nil then
return 'Error: Can not generate a new sha1 hash for empty string. Usage: sha1-hash [yoursecret]'
end
return seawolf.other.hash('sha1', arg[1])
end
},
['sha256-hash'] = {
description = 'Generate a sha256 hash (depends on lsha2 Lua module).',
alias = 'sha256',
exec = function(arg)
local sha2 = require 'lsha2'
if sha2 == nil then
return 'Error: Can not generate a new sha256 hash. Please make sure to have the crypto Lua module installed in your system and try again.'
end
if arg[1] == nil then
return 'Error: Can not generate a new sha256 hash for empty string. Usage: sha256-hash [yoursecret]'
end
return seawolf.other.hash('sha256', arg[1])
end
},
['md5-hash'] = {
description = 'Generate an md5 hash (depends on md5 Lua module).',
alias = 'md5',
exec = function(arg)
local md5 = require 'md5'
if md5 == nil then
return 'Error: Can not generate a new md5 hash. Please make sure to have the crypto Lua module installed in your system and try again.'
end
if arg[1] == nil then
return 'Error: Can not generate a new md5 hash for empty string. Usage: md5-hash [yoursecret]'
end
return seawolf.other.hash('md5', arg[1])
end
},
},
}
return m