#!/usr/bin/lua local cli = require "cli" local plpath = require "pl.path" local nsm = require "volksdata.namespace" local term = require "volksdata.term" local triple = require "volksdata.triple" local graph = require "volksdata.graph" local pkar = require "pocket_archive" local sub = require "pocket_archive.submission" local repo = require "pocket_archive.repo" local gen = require "pocket_archive.generator" local dbg = require "debugger" cli.locale "en_US" -- TODO set with multilingual support. init = cli.command { "Initialize a new Pocket Archive store.", cli.flag "wipe" { "Wipe all preexisting data.", type = cli.boolean, }, function(args) if args.wipe then _ = pkar.reset_store else _ = pkar.store end end } list = cli.command { "List all resource IDs.", function() for s in repo.gr:unique_terms(triple.POS_S):iter() do print(nsm.denormalize_uri(s.data)) end end, } deposit = cli.command { "Deposit a package.", cli.positional "path" { "Path of the laundry list file." }, cli.flag "c,cleanup" { "Remove laundry list and SIP after successful submission.", type = cli.boolean, }, function(args) sub.deposit(args.path, args.cleanup) end } gen_site = cli.command { "Generate a static site from the archive.", function(args) gen.generate_site() end } dump_res = cli.command { "Generate an RDF representation of a resource.", cli.positional "id" { "ID of the resource, prefixed by `par:`", type = cli.string, }, cli.flag "f,format" { "RDF format. `nt` and `ttl` are available.", type = cli.string, default = "ttl", }, cli.flag "o,output" { "Output file. If not specified, output to stdout.", type = cli.string, default = "", }, function(args) local s = term.new_iriref_ns(args.id) local out = repo.serialize_rsrc(s, args.format) if args.output ~= "" then local fh = assert(io.open(args.output, "w")) fh:write(out) fh:close() print("File written to ", args.output) else print(out) end end, } dump_ll = cli.command { "Generate a laundry list for a stored resource.", cli.positional "id" { "ID of the resource, prefixed by `par:`", type = cli.string, }, cli.flag "o,output" { "Output file. If not specified, output to stdout.", type = cli.string, default = "", }, function(args) local s = term.new_iriref_ns(args.id) local out = gen.generate_ll(s) if args.output ~= "" then local fh = assert(io.open(args.output, "w")) fh:write(out) fh:close() print("File written to ", args.output) else print(out) end end } dump_archive = cli.command { "Generate a RDF representation of the full archive.", cli.positional "path" { "Destination file path.", type = cli.string, }, cli.flag "f,format" { "RDF serialization format. One of `ttl` [default], `nt`.", type = cli.string, default = "ttl", }, function(args) repo.dump(args.path, args.format) print ("File written to ", args.path) end, } cli.program { "Pocket Archive command line interface.", }