Wed, 15 Sep 2010 16:53:32 +0100
clix.lua: Filter all log messages except those of the 'error' level unless -v is given
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 |
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
|
9 | local function on_connect(conn) |
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
|
10 | conn:hook("incoming-raw", print); |
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
|
11 | if opts.interactive or opts.stdin 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
|
12 | 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
|
13 | 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
|
14 | 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
|
15 | 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
|
16 | 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
|
17 | 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
|
18 | 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
|
19 | 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
|
20 | 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
|
21 | 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
|
22 | 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 | 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
|
24 | 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
|
25 | }; |
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 | 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
|
27 | 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
|
28 | 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
|
29 | 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
|
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 | 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
|
32 | 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
|
33 | 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
|
34 | }, "*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
|
35 | else |
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 | conn:send(table.concat(arg, " ")); |
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 | 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
|
38 | 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
|
39 | |
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 | 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
|
41 | 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
|
42 | end |