pkar.lua 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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" -- TODO set with multilingual support.
  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. end
  19. }
  20. deposit = cli.command {
  21. "Deposit a package.",
  22. cli.positional "path" {
  23. [[Path of the package root. It must be a directory containing
  24. all the files and folders to be submitted and a `pkar_submission.csv`
  25. file at the top of the folder.]]
  26. },
  27. function(args)
  28. sip = sub.generate_sip(plpath.join(args.path, "pkar_submission.csv"))
  29. sub.deposit(sip)
  30. end
  31. }
  32. gen_site = cli.command {
  33. "Generate a static site from the archive.",
  34. function(args) hgen.generate_site() end
  35. }
  36. gen_rdf = cli.command {
  37. "Generate an RDF representation of a resource.",
  38. cli.positional "id" {
  39. "ID of the resource, prefixed by `par:`",
  40. type = cli.string,
  41. },
  42. cli.flag "f,format" {
  43. "RDF format. `nt` and `ttl` are available.",
  44. type = cli.string,
  45. default = "ttl",
  46. },
  47. function(args)
  48. local s = term.new_iriref_ns(args.id)
  49. print(hgen.generate_rdf(s, args.format))
  50. end,
  51. }
  52. cli.program {
  53. "Pocket Archive command line interface.",
  54. }