clix/vcard.lua

Mon, 27 Aug 2012 00:13:02 +0200

author
Kim Alvefur <zash@zash.se>
date
Mon, 27 Aug 2012 00:13:02 +0200
changeset 98
5ad042476235
parent 67
776d97484dc5
child 155
65dc066a256a
permissions
-rw-r--r--

clix.vcard: Use util.vcard to stringify

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)
582afbb2b23d clix.vcard, squishy: Add plugin that fetches and converts peoples vCards to the text format.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 conn:add_plugin("vcard");
67
776d97484dc5 clix.vcard: Use util.vcard, add ability to change your vcard.
Kim Alvefur <zash@zash.se>
parents: 65
diff changeset
14 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
15 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
16 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
17 conn:close();
776d97484dc5 clix.vcard: Use util.vcard, add ability to change your vcard.
Kim Alvefur <zash@zash.se>
parents: 65
diff changeset
18 end);
776d97484dc5 clix.vcard: Use util.vcard, add ability to change your vcard.
Kim Alvefur <zash@zash.se>
parents: 65
diff changeset
19 else
776d97484dc5 clix.vcard: Use util.vcard, add ability to change your vcard.
Kim Alvefur <zash@zash.se>
parents: 65
diff changeset
20 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
21 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
22 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
23 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
24 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
25 clix_connect(opts, on_connect);
582afbb2b23d clix.vcard, squishy: Add plugin that fetches and converts peoples vCards to the text format.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 end

mercurial