clix/raw.lua

changeset 46
b5d6e443e571
parent 27
5b58c002d6ad
child 68
b7d92ed9c268
equal deleted inserted replaced
45:36f5bf718d3c 46:b5d6e443e571
4 return function (opts, args) 4 return function (opts, args)
5 if opts.short_help then 5 if opts.short_help then
6 print("Send/receive raw XML to/from the server"); 6 print("Send/receive raw XML to/from the server");
7 return; 7 return;
8 end 8 end
9
10 local send_xml;
11 if opts.stdin then
12 send_xml = io.read("*a");
13 end
14
9 local function on_connect(conn) 15 local function on_connect(conn)
10 conn:hook("incoming-raw", print); 16 conn:hook("incoming-raw", function (data) print(data) end);
11 if opts.interactive or opts.stdin then 17 if opts.interactive then
12 local stdin = { 18 local stdin = {
13 getfd = function () return 0; end; 19 getfd = function () return 0; end;
14 dirty = function (self) return false; end; 20 dirty = function (self) return false; end;
15 settimeout = function () end; 21 settimeout = function () end;
16 send = function (_, d) return #d, 0; end; 22 send = function (_, d) return #d, 0; end;
31 end 37 end
32 stdin = require "net.server".wrapclient(stdin, "stdin", 0, { 38 stdin = require "net.server".wrapclient(stdin, "stdin", 0, {
33 onincoming = on_incoming, ondisconnect = function () end 39 onincoming = on_incoming, ondisconnect = function () end
34 }, "*l"); 40 }, "*l");
35 else 41 else
36 conn:send(table.concat(arg, " ")); 42 if send_xml then
43 conn:send(send_xml);
44 else
45 conn:send(table.concat(arg, " "));
46 end
37 conn:close(); 47 conn:close();
38 end 48 end
39 49
40 end 50 end
41 return clix_connect(opts, on_connect); 51 return clix_connect(opts, on_connect);

mercurial