clix/raw.lua

Tue, 22 Feb 2011 20:52:22 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Tue, 22 Feb 2011 20:52:22 +0000
changeset 46
b5d6e443e571
parent 27
5b58c002d6ad
child 68
b7d92ed9c268
permissions
-rw-r--r--

raw: If using --stdin and not --interactive then buffer all data before connecting, more reliable in a non-interactive environment

19
3a0a156e0a79 clix.raw: New command to set up a raw XML in/out session with the server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 short_opts.i = "interactive";
3a0a156e0a79 clix.raw: New command to set up a raw XML in/out session with the server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 short_opts.e = "echo";
3a0a156e0a79 clix.raw: New command to set up a raw XML in/out session with the server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3
3a0a156e0a79 clix.raw: New command to set up a raw XML in/out session with the server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 return function (opts, args)
27
5b58c002d6ad clix.*: Add --short-help and make sure they are working correctly
Matthew Wild <mwild1@gmail.com>
parents: 23
diff changeset
5 if opts.short_help then
5b58c002d6ad clix.*: Add --short-help and make sure they are working correctly
Matthew Wild <mwild1@gmail.com>
parents: 23
diff changeset
6 print("Send/receive raw XML to/from the server");
5b58c002d6ad clix.*: Add --short-help and make sure they are working correctly
Matthew Wild <mwild1@gmail.com>
parents: 23
diff changeset
7 return;
5b58c002d6ad clix.*: Add --short-help and make sure they are working correctly
Matthew Wild <mwild1@gmail.com>
parents: 23
diff changeset
8 end
46
b5d6e443e571 raw: If using --stdin and not --interactive then buffer all data before connecting, more reliable in a non-interactive environment
Matthew Wild <mwild1@gmail.com>
parents: 27
diff changeset
9
b5d6e443e571 raw: If using --stdin and not --interactive then buffer all data before connecting, more reliable in a non-interactive environment
Matthew Wild <mwild1@gmail.com>
parents: 27
diff changeset
10 local send_xml;
b5d6e443e571 raw: If using --stdin and not --interactive then buffer all data before connecting, more reliable in a non-interactive environment
Matthew Wild <mwild1@gmail.com>
parents: 27
diff changeset
11 if opts.stdin then
b5d6e443e571 raw: If using --stdin and not --interactive then buffer all data before connecting, more reliable in a non-interactive environment
Matthew Wild <mwild1@gmail.com>
parents: 27
diff changeset
12 send_xml = io.read("*a");
b5d6e443e571 raw: If using --stdin and not --interactive then buffer all data before connecting, more reliable in a non-interactive environment
Matthew Wild <mwild1@gmail.com>
parents: 27
diff changeset
13 end
b5d6e443e571 raw: If using --stdin and not --interactive then buffer all data before connecting, more reliable in a non-interactive environment
Matthew Wild <mwild1@gmail.com>
parents: 27
diff changeset
14
19
3a0a156e0a79 clix.raw: New command to set up a raw XML in/out session with the server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 local function on_connect(conn)
46
b5d6e443e571 raw: If using --stdin and not --interactive then buffer all data before connecting, more reliable in a non-interactive environment
Matthew Wild <mwild1@gmail.com>
parents: 27
diff changeset
16 conn:hook("incoming-raw", function (data) print(data) end);
b5d6e443e571 raw: If using --stdin and not --interactive then buffer all data before connecting, more reliable in a non-interactive environment
Matthew Wild <mwild1@gmail.com>
parents: 27
diff changeset
17 if opts.interactive then
19
3a0a156e0a79 clix.raw: New command to set up a raw XML in/out session with the server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 local stdin = {
3a0a156e0a79 clix.raw: New command to set up a raw XML in/out session with the server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 getfd = function () return 0; end;
3a0a156e0a79 clix.raw: New command to set up a raw XML in/out session with the server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 dirty = function (self) return false; end;
3a0a156e0a79 clix.raw: New command to set up a raw XML in/out session with the server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 settimeout = function () end;
3a0a156e0a79 clix.raw: New command to set up a raw XML in/out session with the server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 send = function (_, d) return #d, 0; end;
3a0a156e0a79 clix.raw: New command to set up a raw XML in/out session with the server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 close = function () end;
3a0a156e0a79 clix.raw: New command to set up a raw XML in/out session with the server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 receive = function (_, patt)
3a0a156e0a79 clix.raw: New command to set up a raw XML in/out session with the server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 local data = io.stdin:read(patt);
3a0a156e0a79 clix.raw: New command to set up a raw XML in/out session with the server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 if opts.echo then
3a0a156e0a79 clix.raw: New command to set up a raw XML in/out session with the server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 io.write(data, patt == "*l" and "\n" or "");
3a0a156e0a79 clix.raw: New command to set up a raw XML in/out session with the server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 end
3a0a156e0a79 clix.raw: New command to set up a raw XML in/out session with the server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 return data;
3a0a156e0a79 clix.raw: New command to set up a raw XML in/out session with the server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 end
3a0a156e0a79 clix.raw: New command to set up a raw XML in/out session with the server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 };
3a0a156e0a79 clix.raw: New command to set up a raw XML in/out session with the server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 local function on_incoming(stdin, data)
3a0a156e0a79 clix.raw: New command to set up a raw XML in/out session with the server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 conn:send(data);
3a0a156e0a79 clix.raw: New command to set up a raw XML in/out session with the server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 if not opts.interactive then
3a0a156e0a79 clix.raw: New command to set up a raw XML in/out session with the server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 conn:close();
3a0a156e0a79 clix.raw: New command to set up a raw XML in/out session with the server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 end
3a0a156e0a79 clix.raw: New command to set up a raw XML in/out session with the server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 end
3a0a156e0a79 clix.raw: New command to set up a raw XML in/out session with the server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 stdin = require "net.server".wrapclient(stdin, "stdin", 0, {
3a0a156e0a79 clix.raw: New command to set up a raw XML in/out session with the server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 onincoming = on_incoming, ondisconnect = function () end
3a0a156e0a79 clix.raw: New command to set up a raw XML in/out session with the server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 }, "*l");
3a0a156e0a79 clix.raw: New command to set up a raw XML in/out session with the server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 else
46
b5d6e443e571 raw: If using --stdin and not --interactive then buffer all data before connecting, more reliable in a non-interactive environment
Matthew Wild <mwild1@gmail.com>
parents: 27
diff changeset
42 if send_xml then
b5d6e443e571 raw: If using --stdin and not --interactive then buffer all data before connecting, more reliable in a non-interactive environment
Matthew Wild <mwild1@gmail.com>
parents: 27
diff changeset
43 conn:send(send_xml);
b5d6e443e571 raw: If using --stdin and not --interactive then buffer all data before connecting, more reliable in a non-interactive environment
Matthew Wild <mwild1@gmail.com>
parents: 27
diff changeset
44 else
b5d6e443e571 raw: If using --stdin and not --interactive then buffer all data before connecting, more reliable in a non-interactive environment
Matthew Wild <mwild1@gmail.com>
parents: 27
diff changeset
45 conn:send(table.concat(arg, " "));
b5d6e443e571 raw: If using --stdin and not --interactive then buffer all data before connecting, more reliable in a non-interactive environment
Matthew Wild <mwild1@gmail.com>
parents: 27
diff changeset
46 end
19
3a0a156e0a79 clix.raw: New command to set up a raw XML in/out session with the server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 conn:close();
3a0a156e0a79 clix.raw: New command to set up a raw XML in/out session with the server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 end
3a0a156e0a79 clix.raw: New command to set up a raw XML in/out session with the server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49
3a0a156e0a79 clix.raw: New command to set up a raw XML in/out session with the server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 end
3a0a156e0a79 clix.raw: New command to set up a raw XML in/out session with the server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 return clix_connect(opts, on_connect);
3a0a156e0a79 clix.raw: New command to set up a raw XML in/out session with the server
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 end

mercurial