pkar.lua 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. local res_gr = hgen.get_graph(s)
  52. print(res_gr:encode(args.format))
  53. end,
  54. }
  55. cli.program {
  56. "Pocket Archive command line interface.",
  57. }