pkar.lua 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/bin/lua
  2. local cli = require "cli"
  3. local plpath = require "pl.path"
  4. local term = require "volksdata.term"
  5. local pkar = require "pocket_archive"
  6. local sub = require "pocket_archive.submission"
  7. local hgen = require "pocket_archive.html_generator"
  8. cli.locale "en_US"
  9. init = cli.command {
  10. "Initialize a new Pocket Archive store.",
  11. cli.flag "wipe" {
  12. "Wipe all preexisting data.",
  13. type = cli.boolean,
  14. },
  15. function(args)
  16. if args.wipe then _ = pkar.reset_store
  17. else _ = pkar.store end
  18. _ = nil
  19. collectgarbage()
  20. end
  21. }
  22. submit = cli.command {
  23. "Submit a package.",
  24. cli.positional "path" {
  25. [[Path of the package root. It must be a directory containing
  26. all the files and folders to be submitted and a `pkar_submission.csv`
  27. file at the top of the folder.]]
  28. },
  29. function(args)
  30. sip = sub.generate_sip(plpath.join(args.path, "pkar_submission.csv"))
  31. sub.deposit(sip)
  32. end
  33. }
  34. gen_site = cli.command {
  35. "Generate a static site from the archive.",
  36. function(args) hgen.generate_site() end
  37. }
  38. gen_rdf = cli.command {
  39. "Generate an RDF representation of a resource.",
  40. cli.positional "id" {
  41. "ID of the resource, prefixed by `par:`",
  42. type = cli.string,
  43. },
  44. cli.flag "f,format" {
  45. "RDF format. `nt` and `ttl` are available.",
  46. type = cli.string,
  47. default = "ttl",
  48. },
  49. function(args)
  50. local s = term.new_iriref_ns(args.id)
  51. print(hgen.generate_rdf(s, args.format))
  52. end,
  53. }
  54. cli.program {
  55. "Pocket Archive command line interface.",
  56. }