clix/vcard.lua

Sat, 10 Apr 2021 00:49:46 +0200

author
Kim Alvefur <zash@zash.se>
date
Sat, 10 Apr 2021 00:49:46 +0200
changeset 155
65dc066a256a
parent 98
5ad042476235
child 168
75e8ca131178
permissions
-rw-r--r--

clix.vcard: Use alternate method of enabling plugin

Dunno if this is better, but I've had this like this uncommitted for so
long.

64
582afbb2b23d clix.vcard, squishy: Add plugin that fetches and converts peoples vCards to the text format.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 local t_insert, t_concat = table.insert, table.concat;
98
5ad042476235 clix.vcard: Use util.vcard to stringify
Kim Alvefur <zash@zash.se>
parents: 67
diff changeset
2 local vcard_to_text = require"util.vcard".to_text;
64
582afbb2b23d clix.vcard, squishy: Add plugin that fetches and converts peoples vCards to the text format.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3
582afbb2b23d clix.vcard, squishy: Add plugin that fetches and converts peoples vCards to the text format.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 return function (opts, arg)
582afbb2b23d clix.vcard, squishy: Add plugin that fetches and converts peoples vCards to the text format.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 if opts.short_help then
67
776d97484dc5 clix.vcard: Use util.vcard, add ability to change your vcard.
Kim Alvefur <zash@zash.se>
parents: 65
diff changeset
6 print("Fetch someones vCard or set your own");
64
582afbb2b23d clix.vcard, squishy: Add plugin that fetches and converts peoples vCards to the text format.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 return;
582afbb2b23d clix.vcard, squishy: Add plugin that fetches and converts peoples vCards to the text format.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 end
67
776d97484dc5 clix.vcard: Use util.vcard, add ability to change your vcard.
Kim Alvefur <zash@zash.se>
parents: 65
diff changeset
9 if ((#arg == 0 and not opts.set) or opts.help) then
64
582afbb2b23d clix.vcard, squishy: Add plugin that fetches and converts peoples vCards to the text format.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 return 0;
582afbb2b23d clix.vcard, squishy: Add plugin that fetches and converts peoples vCards to the text format.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 end
582afbb2b23d clix.vcard, squishy: Add plugin that fetches and converts peoples vCards to the text format.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 local function on_connect(conn)
67
776d97484dc5 clix.vcard: Use util.vcard, add ability to change your vcard.
Kim Alvefur <zash@zash.se>
parents: 65
diff changeset
13 if not opts.set then -- get
776d97484dc5 clix.vcard: Use util.vcard, add ability to change your vcard.
Kim Alvefur <zash@zash.se>
parents: 65
diff changeset
14 conn:get_vcard(arg[1], function(vCard)
98
5ad042476235 clix.vcard: Use util.vcard to stringify
Kim Alvefur <zash@zash.se>
parents: 67
diff changeset
15 print(vCard and vcard_to_text(vCard) or "No vCard returned")
67
776d97484dc5 clix.vcard: Use util.vcard, add ability to change your vcard.
Kim Alvefur <zash@zash.se>
parents: 65
diff changeset
16 conn:close();
776d97484dc5 clix.vcard: Use util.vcard, add ability to change your vcard.
Kim Alvefur <zash@zash.se>
parents: 65
diff changeset
17 end);
776d97484dc5 clix.vcard: Use util.vcard, add ability to change your vcard.
Kim Alvefur <zash@zash.se>
parents: 65
diff changeset
18 else
776d97484dc5 clix.vcard: Use util.vcard, add ability to change your vcard.
Kim Alvefur <zash@zash.se>
parents: 65
diff changeset
19 conn:set_vcard(opts.stdin and io.stdin:read"*a"
776d97484dc5 clix.vcard: Use util.vcard, add ability to change your vcard.
Kim Alvefur <zash@zash.se>
parents: 65
diff changeset
20 or (opts.file and io.open(opts.file):read"*a") or arg[1],
776d97484dc5 clix.vcard: Use util.vcard, add ability to change your vcard.
Kim Alvefur <zash@zash.se>
parents: 65
diff changeset
21 function() conn:close() end)
776d97484dc5 clix.vcard: Use util.vcard, add ability to change your vcard.
Kim Alvefur <zash@zash.se>
parents: 65
diff changeset
22 end
64
582afbb2b23d clix.vcard, squishy: Add plugin that fetches and converts peoples vCards to the text format.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 end
155
65dc066a256a clix.vcard: Use alternate method of enabling plugin
Kim Alvefur <zash@zash.se>
parents: 98
diff changeset
24 clix_connect(opts, on_connect, { "vcard" });
64
582afbb2b23d clix.vcard, squishy: Add plugin that fetches and converts peoples vCards to the text format.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 end

mercurial