diff options
-rw-r--r-- | db.lua | 43 | ||||
-rwxr-xr-x | todb.lua | 20 |
2 files changed, 63 insertions, 0 deletions
@@ -0,0 +1,43 @@ +--[[-- + + JSON file database. + +--]]-- + +local inspect = require "ext.inspect" + +local cjson = require "cjson" + +local pcall = pcall + +local io = require "io" +local iostdout = io.stdout + +local common = require "common" +local common_status = common.status +local status_ok = common_status.codes.ok +local status_error = common_status.codes.error +local println = common.println +local errorln = common.errorln +local noiseln = common.noiseln +local debugln = common.debugln + +------------------------------------------------------------------------------- +--- API +------------------------------------------------------------------------------- + +local output_calendar = function (cal, fh) + fh = fh or iostdout + local jsenc = cjson.new () + local ok, str = pcall (jsenc.encode, cal) + if ok == false then + errorln ("todb: failed to serialize calendar: %s", str) + return status_error + end + fh:write (str) + return status_ok +end + +return { output_calendar = output_calendar + } + diff --git a/todb.lua b/todb.lua new file mode 100755 index 0000000..50799ec --- /dev/null +++ b/todb.lua @@ -0,0 +1,20 @@ +#!/usr/bin/env lua +local cal = require "cal" +local db = require "db" +local common = require "common" + +common.set_verbosity (1) + +local main = function (argv) + local ok, parsed = cal.parse_stdin () + if not ok then + return -1 + end + + local ok = db.output_calendar (parsed) + + return ok and 0 or -1 +end + +os.exit (main ()) + |