|
1 short_opts.i = "interactive"; |
|
2 |
1 return function (opts, arg) |
3 return function (opts, arg) |
2 if #arg == 0 or opts.help then |
4 if (#arg == 0 or opts.help) and not opts.interactive then |
3 return 0; |
5 return 0; |
4 end |
6 end |
5 local function on_connect(conn) |
7 local function on_connect(conn) |
6 conn:send(verse.message({ to = opts.to, type = opts.type or "chat" }):body(table.concat(arg, " "))); |
8 local function send_message(_, text) |
7 conn:close(); |
9 conn:send(verse.message({ to = opts.to, type = opts.type or "chat" }):body(text)); |
|
10 end |
|
11 if opts.interactive then |
|
12 -- Fake socket object around stdin |
|
13 local stdin = { |
|
14 getfd = function () return 0; end; |
|
15 dirty = function (self) return false; end; |
|
16 settimeout = function () end; |
|
17 send = function (_, d) return #d, 0; end; |
|
18 close = function () end; |
|
19 receive = function (_, patt) |
|
20 local data = io.stdin:read(patt); |
|
21 io.write(data, patt == "*l" and "\n" or ""); |
|
22 return data; |
|
23 end |
|
24 }; |
|
25 stdin = require "net.server".wrapclient(stdin, "stdin", 0, { onincoming = send_message, ondisconnect = function () end }, "*l"); |
|
26 else |
|
27 send_message(nil, table.concat(arg, " ")); |
|
28 conn:close(); |
|
29 end |
8 end |
30 end |
9 clix_connect(opts, on_connect); |
31 clix_connect(opts, on_connect); |
10 end |
32 end |