clix/vcard.lua

Sat, 24 Jun 2023 09:59:07 +0200

author
Kim Alvefur <zash@zash.se>
date
Sat, 24 Jun 2023 09:59:07 +0200
changeset 170
0d561f921c13
parent 168
75e8ca131178
permissions
-rw-r--r--

clix.adhoc: Move stanza to dataform converter here

Removes the need for verse to have a custom util.dataforms fork only for
this

local t_insert, t_concat = table.insert, table.concat;
local vcard_to_text = require"verse.util.vcard".to_text;

return function (opts, arg)
	if opts.short_help then
		print("Fetch someones vCard or set your own");
		return;
	end
	if ((#arg == 0 and not opts.set) or opts.help) then
		return 0;
	end
	local function on_connect(conn)
		if not opts.set then -- get
			conn:get_vcard(arg[1], function(vCard)
				print(vCard and vcard_to_text(vCard) or "No vCard returned")
				conn:close();
			end);
		else
			conn:set_vcard(opts.stdin and io.stdin:read"*a"
				or (opts.file and io.open(opts.file):read"*a") or arg[1],
				function() conn:close() end)
		end
	end
	clix_connect(opts, on_connect, { "vcard" });
end

mercurial