Fri, 26 May 2023 22:39:38 +0200
Update to handle Prosody module namespacing
This enables installation methods other than squish, such as luarocks
164 | 1 | local verse = require "verse"; |
9
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
2 | short_opts.i = "interactive"; |
18
6ad3ea055905
clix.send: Add --stdin flag to indicate to read data from stdin (but not interactively)
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
3 | short_opts.e = "echo"; |
9
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
4 | |
0 | 5 | return function (opts, arg) |
27
5b58c002d6ad
clix.*: Add --short-help and make sure they are working correctly
Matthew Wild <mwild1@gmail.com>
parents:
21
diff
changeset
|
6 | if opts.short_help then |
5b58c002d6ad
clix.*: Add --short-help and make sure they are working correctly
Matthew Wild <mwild1@gmail.com>
parents:
21
diff
changeset
|
7 | print("Send messages"); |
5b58c002d6ad
clix.*: Add --short-help and make sure they are working correctly
Matthew Wild <mwild1@gmail.com>
parents:
21
diff
changeset
|
8 | return; |
5b58c002d6ad
clix.*: Add --short-help and make sure they are working correctly
Matthew Wild <mwild1@gmail.com>
parents:
21
diff
changeset
|
9 | end |
9
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
10 | if (#arg == 0 or opts.help) and not opts.interactive then |
0 | 11 | return 0; |
12 | end | |
13 | local function on_connect(conn) | |
18
6ad3ea055905
clix.send: Add --stdin flag to indicate to read data from stdin (but not interactively)
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
14 | local function send_message(text) |
21
cdeb02d9546d
clix, clix.send: Support for chatrooms (-c/--chatroom with --nick=somenick)
Matthew Wild <mwild1@gmail.com>
parents:
18
diff
changeset
|
15 | conn:send(verse.message({ to = opts.to, |
cdeb02d9546d
clix, clix.send: Support for chatrooms (-c/--chatroom with --nick=somenick)
Matthew Wild <mwild1@gmail.com>
parents:
18
diff
changeset
|
16 | type = opts.type or (opts.chatroom and "groupchat") or "chat" }) |
cdeb02d9546d
clix, clix.send: Support for chatrooms (-c/--chatroom with --nick=somenick)
Matthew Wild <mwild1@gmail.com>
parents:
18
diff
changeset
|
17 | :body(text)); |
9
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
18 | end |
18
6ad3ea055905
clix.send: Add --stdin flag to indicate to read data from stdin (but not interactively)
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
19 | if opts.interactive or opts.stdin then |
9
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
20 | -- Fake socket object around stdin |
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
21 | local stdin = { |
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
22 | getfd = function () return 0; end; |
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
23 | dirty = function (self) return false; end; |
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
24 | settimeout = function () end; |
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
25 | send = function (_, d) return #d, 0; end; |
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
26 | close = function () end; |
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
27 | receive = function (_, patt) |
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
28 | local data = io.stdin:read(patt); |
36
0712fda16ab6
close connection when no more input is available in interactive mode
Hubert Chathi <hubert@uhoreg.ca>
parents:
27
diff
changeset
|
29 | if data == nil then |
0712fda16ab6
close connection when no more input is available in interactive mode
Hubert Chathi <hubert@uhoreg.ca>
parents:
27
diff
changeset
|
30 | conn:close(); |
0712fda16ab6
close connection when no more input is available in interactive mode
Hubert Chathi <hubert@uhoreg.ca>
parents:
27
diff
changeset
|
31 | end |
18
6ad3ea055905
clix.send: Add --stdin flag to indicate to read data from stdin (but not interactively)
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
32 | if opts.echo then |
6ad3ea055905
clix.send: Add --stdin flag to indicate to read data from stdin (but not interactively)
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
33 | io.write(data, patt == "*l" and "\n" or ""); |
6ad3ea055905
clix.send: Add --stdin flag to indicate to read data from stdin (but not interactively)
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
34 | end |
9
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
35 | return data; |
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
36 | end |
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
37 | }; |
18
6ad3ea055905
clix.send: Add --stdin flag to indicate to read data from stdin (but not interactively)
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
38 | local function on_incoming(stdin, text) |
6ad3ea055905
clix.send: Add --stdin flag to indicate to read data from stdin (but not interactively)
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
39 | send_message(text); |
6ad3ea055905
clix.send: Add --stdin flag to indicate to read data from stdin (but not interactively)
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
40 | if not opts.interactive then |
6ad3ea055905
clix.send: Add --stdin flag to indicate to read data from stdin (but not interactively)
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
41 | conn:close(); |
6ad3ea055905
clix.send: Add --stdin flag to indicate to read data from stdin (but not interactively)
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
42 | end |
6ad3ea055905
clix.send: Add --stdin flag to indicate to read data from stdin (but not interactively)
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
43 | end |
168
75e8ca131178
Update to handle Prosody module namespacing
Kim Alvefur <zash@zash.se>
parents:
164
diff
changeset
|
44 | stdin = verse.server.wrapclient(stdin, "stdin", 0, { |
18
6ad3ea055905
clix.send: Add --stdin flag to indicate to read data from stdin (but not interactively)
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
45 | onincoming = on_incoming, ondisconnect = function () end |
6ad3ea055905
clix.send: Add --stdin flag to indicate to read data from stdin (but not interactively)
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
46 | }, "*l"); |
9
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
47 | else |
18
6ad3ea055905
clix.send: Add --stdin flag to indicate to read data from stdin (but not interactively)
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
48 | send_message(table.concat(arg, " ")); |
9
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
49 | conn:close(); |
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
50 | end |
0 | 51 | end |
52 | clix_connect(opts, on_connect); | |
53 | end |