pkar.lua 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/usr/bin/lua
  2. local cli = require "cli"
  3. local plpath = require "pl.path"
  4. local nsm = require "volksdata.namespace"
  5. local term = require "volksdata.term"
  6. local triple = require "volksdata.triple"
  7. local graph = require "volksdata.graph"
  8. local pkar = require "pocket_archive"
  9. local sub = require "pocket_archive.submission"
  10. local hgen = require "pocket_archive.html_generator"
  11. cli.locale "en_US" -- TODO set with multilingual support.
  12. init = cli.command {
  13. "Initialize a new Pocket Archive store.",
  14. cli.flag "wipe" {
  15. "Wipe all preexisting data.",
  16. type = cli.boolean,
  17. },
  18. function(args)
  19. if args.wipe then _ = pkar.reset_store
  20. else _ = pkar.store end
  21. end
  22. }
  23. list = cli.command {
  24. "List all resource IDs.",
  25. function()
  26. local gr = graph.new(pkar.store, term.DEFAULT_CTX)
  27. for _, s in pairs(gr:unique_terms(triple.POS_S)) do
  28. print(nsm.denormalize_uri(s.data))
  29. end
  30. end,
  31. }
  32. deposit = cli.command {
  33. "Deposit a package.",
  34. cli.positional "path" {
  35. [[Path of the package root. It must be a directory containing
  36. all the files and folders to be submitted and a `pkar_submission.csv`
  37. file at the top of the folder.]]
  38. },
  39. function(args)
  40. sip = sub.generate_sip(plpath.join(args.path, "pkar_submission.csv"))
  41. sub.deposit(sip)
  42. end
  43. }
  44. gen_site = cli.command {
  45. "Generate a static site from the archive.",
  46. function(args) hgen.generate_site() end
  47. }
  48. gen_rdf = cli.command {
  49. "Generate an RDF representation of a resource.",
  50. cli.positional "id" {
  51. "ID of the resource, prefixed by `par:`",
  52. type = cli.string,
  53. },
  54. cli.flag "f,format" {
  55. "RDF format. `nt` and `ttl` are available.",
  56. type = cli.string,
  57. default = "ttl",
  58. },
  59. function(args)
  60. local s = term.new_iriref_ns(args.id)
  61. print(hgen.generate_rdf(s, args.format))
  62. end,
  63. }
  64. gen_ll = cli.command {
  65. "Generate a laundry list for a stored resource.",
  66. cli.positional "id" {
  67. "ID of the resource, prefixed by `par:`",
  68. type = cli.string,
  69. },
  70. function(args)
  71. local s = term.new_iriref_ns(args.id)
  72. print(hgen.generate_ll(s))
  73. end
  74. }
  75. cli.program {
  76. "Pocket Archive command line interface.",
  77. }