minetest.scm 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2014 David Thompson <davet@gnu.org>
  3. ;;; Copyright © 2018 Ricardo Wurmus <rekado@elephly.net>
  4. ;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be>
  5. ;;;
  6. ;;; This file is part of GNU Guix.
  7. ;;;
  8. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  9. ;;; under the terms of the GNU General Public License as published by
  10. ;;; the Free Software Foundation; either version 3 of the License, or (at
  11. ;;; your option) any later version.
  12. ;;;
  13. ;;; GNU Guix is distributed in the hope that it will be useful, but
  14. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;;; GNU General Public License for more details.
  17. ;;;
  18. ;;; You should have received a copy of the GNU General Public License
  19. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  20. (define-module (guix scripts import minetest)
  21. #:use-module (guix ui)
  22. #:use-module (guix utils)
  23. #:use-module (guix scripts)
  24. #:use-module (guix import minetest)
  25. #:use-module (guix import utils)
  26. #:use-module (guix scripts import)
  27. #:use-module (srfi srfi-1)
  28. #:use-module (srfi srfi-11)
  29. #:use-module (srfi srfi-37)
  30. #:use-module (ice-9 match)
  31. #:use-module (ice-9 format)
  32. #:export (guix-import-minetest))
  33. ;;;
  34. ;;; Command-line options.
  35. ;;;
  36. (define %default-options
  37. `((sort . ,%default-sort-key)))
  38. (define (show-help)
  39. (display (G_ "Usage: guix import minetest AUTHOR/NAME
  40. Import and convert the Minetest mod NAME by AUTHOR from ContentDB.\n"))
  41. (display (G_ "
  42. -h, --help display this help and exit"))
  43. (display (G_ "
  44. -r, --recursive import packages recursively"))
  45. (display (G_ "
  46. -V, --version display version information and exit"))
  47. (display (G_ "
  48. --sort=KEY when choosing between multiple implementations,
  49. choose the one with the highest value for KEY
  50. (one of \"score\" (standard) or \"downloads\")"))
  51. (newline)
  52. (show-bug-report-information))
  53. (define (verify-sort-order sort)
  54. "Verify SORT can be used to sort mods by."
  55. (unless (member sort '("score" "downloads" "reviews"))
  56. (leave (G_ "~a: not a valid key to sort by~%") sort))
  57. sort)
  58. (define %options
  59. ;; Specification of the command-line options.
  60. (cons* (option '(#\h "help") #f #f
  61. (lambda args
  62. (show-help)
  63. (exit 0)))
  64. (option '(#\V "version") #f #f
  65. (lambda args
  66. (show-version-and-exit "guix import minetest")))
  67. (option '(#\r "recursive") #f #f
  68. (lambda (opt name arg result)
  69. (alist-cons 'recursive #t result)))
  70. (option '("sort") #t #f
  71. (lambda (opt name arg result)
  72. (alist-cons 'sort (verify-sort-order arg) result)))
  73. %standard-import-options))
  74. ;;;
  75. ;;; Entry point.
  76. ;;;
  77. (define (guix-import-minetest . args)
  78. (define (parse-options)
  79. ;; Return the alist of option values.
  80. (args-fold* args %options
  81. (lambda (opt name arg result)
  82. (leave (G_ "~A: unrecognized option~%") name))
  83. (lambda (arg result)
  84. (alist-cons 'argument arg result))
  85. %default-options))
  86. (let* ((opts (parse-options))
  87. (args (filter-map (match-lambda
  88. (('argument . value)
  89. value)
  90. (_ #f))
  91. (reverse opts))))
  92. (match args
  93. ((name)
  94. (with-error-handling
  95. (let* ((sort (assoc-ref opts 'sort))
  96. (author/name (elaborate-contentdb-name name #:sort sort)))
  97. (if (assoc-ref opts 'recursive)
  98. ;; Recursive import
  99. (filter-map package->definition
  100. (minetest-recursive-import author/name #:sort sort))
  101. ;; Single import
  102. (minetest->guix-package author/name #:sort sort)))))
  103. (()
  104. (leave (G_ "too few arguments~%")))
  105. ((many ...)
  106. (leave (G_ "too many arguments~%"))))))