cran.scm 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2014 Eric Bavier <bavier@member.fsf.org>
  3. ;;; Copyright © 2015, 2017, 2019, 2020 Ricardo Wurmus <rekado@elephly.net>
  4. ;;; Copyright © 2020 Martin Becze <mjbecze@riseup.net>
  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 cran)
  21. #:use-module (guix ui)
  22. #:use-module (guix utils)
  23. #:use-module (guix scripts)
  24. #:use-module (guix import cran)
  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-cran))
  33. ;;;
  34. ;;; Command-line options.
  35. ;;;
  36. (define %default-options
  37. '())
  38. (define (show-help)
  39. (display (G_ "Usage: guix import cran PACKAGE-NAME
  40. Import and convert the CRAN package for PACKAGE-NAME.\n"))
  41. (display (G_ "
  42. -a, --archive=ARCHIVE specify the archive repository"))
  43. (display (G_ "
  44. -h, --help display this help and exit"))
  45. (display (G_ "
  46. -r, --recursive import packages recursively"))
  47. (display (G_ "
  48. -s, --style=STYLE choose output style, either specification or variable"))
  49. (display (G_ "
  50. -V, --version display version information and exit"))
  51. (newline)
  52. (show-bug-report-information))
  53. (define %options
  54. ;; Specification of the command-line options.
  55. (cons* (option '(#\h "help") #f #f
  56. (lambda args
  57. (show-help)
  58. (exit 0)))
  59. (option '(#\V "version") #f #f
  60. (lambda args
  61. (show-version-and-exit "guix import cran")))
  62. (option '(#\a "archive") #t #f
  63. (lambda (opt name arg result)
  64. (alist-cons 'repo (string->symbol arg)
  65. (alist-delete 'repo result))))
  66. (option '(#\s "style") #t #f
  67. (lambda (opt name arg result)
  68. (alist-cons 'style (string->symbol arg)
  69. (alist-delete 'style result))))
  70. (option '(#\r "recursive") #f #f
  71. (lambda (opt name arg result)
  72. (alist-cons 'recursive #t result)))
  73. %standard-import-options))
  74. ;;;
  75. ;;; Entry point.
  76. ;;;
  77. (define (guix-import-cran . 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. (parameterize ((%input-style (assoc-ref opts 'style)))
  93. (match args
  94. ((package-name)
  95. (if (assoc-ref opts 'recursive)
  96. ;; Recursive import
  97. (with-error-handling
  98. (map package->definition
  99. (filter identity
  100. (cran-recursive-import package-name
  101. #:repo (or (assoc-ref opts 'repo) 'cran)))))
  102. ;; Single import
  103. (let ((sexp (cran->guix-package package-name
  104. #:repo (or (assoc-ref opts 'repo) 'cran))))
  105. (unless sexp
  106. (leave (G_ "failed to download description for package '~a'~%")
  107. package-name))
  108. sexp)))
  109. (()
  110. (leave (G_ "too few arguments~%")))
  111. ((many ...)
  112. (leave (G_ "too many arguments~%")))))))