cpan.scm 2.9 KB

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