| 1 | local t_insert, t_concat = table.insert, table.concat; |
| 2 | local vcard_to_text = require"verse.util.vcard".to_text; |
| 3 | |
| 4 | return function (opts, arg) |
| 5 | if opts.short_help then |
| 6 | print("Fetch someones vCard or set your own"); |
| 7 | return; |
| 8 | end |
| 9 | if ((#arg == 0 and not opts.set) or opts.help) then |
| 10 | return 0; |
| 11 | end |
| 12 | local function on_connect(conn) |
| 13 | if not opts.set then -- get |
| 14 | conn:get_vcard(arg[1], function(vCard) |
| 15 | print(vCard and vcard_to_text(vCard) or "No vCard returned") |
| 16 | conn:close(); |
| 17 | end); |
| 18 | else |
| 19 | conn:set_vcard(opts.stdin and io.stdin:read"*a" |
| 20 | or (opts.file and io.open(opts.file):read"*a") or arg[1], |
| 21 | function() conn:close() end) |
| 22 | end |
| 23 | end |
| 24 | clix_connect(opts, on_connect, { "vcard" }); |
| 25 | end |