cran.scm 3.8 KB

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