summaryrefslogtreecommitdiffstats
path: root/bin/acf-cli
blob: dab8c0f86978132a723888f721d929dd8c9fa98b (plain)
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
#!/usr/bin/lua
if #arg == 0 then
	print([[ACF Client interface

Usage: acf-cli [action] [parameter]...

Actions are of the form "prefix/controller/action"
Parameters are of the form "parameter=value"
	list and multi select parameters are of the form "parameter[1]=value"
	to set a list or multi to blank use "parameter" without any value
	parameters within groups are of the form "group.parameter=value"
	boolean parameters should be specified as "true" or "false"

Example:
acf-cli acf-util/password/newuser password="test123" password_confirm="test123" roles[1]="ADMIN" userid="root" submit="Create"

For forms, remember to pass in "submit" as a parameter with an appropriate value from the form "option" (see Create in example above).
Output will be a serialized Lua table unless specified otherwise with "viewtype" parameter.
	]])
	return
end

posix = require("posix")
mvc = require("acf.mvc")

FRAMEWORK=mvc:new()
FRAMEWORK:read_config("acf") 
APP=FRAMEWORK:new("acf_cli")

-- command line will have URI-type string defining prefix/controller/action
-- followed by parameters
local p,c,a = APP.parse_path_info(arg[1])
local clientdata = {}
for i=2,#arg do
	local a,v = string.match(arg[i], "([^=]*)=(.*)")
	if v then
		clientdata[a] = v
	else
		clientdata[arg[i]] = true
	end
end
APP:dispatch(p,c,a,clientdata)
APP:destroy()
FRAMEWORK:destroy()