cpan.scm 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2014 Eric Bavier <bavier@member.fsf.org>
  3. ;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
  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 cpan)
  20. #:use-module (guix ui)
  21. #:use-module (guix utils)
  22. #:use-module (guix scripts)
  23. #:use-module (guix import cpan)
  24. #:use-module (guix scripts import)
  25. #:use-module (srfi srfi-1)
  26. #:use-module (srfi srfi-11)
  27. #:use-module (srfi srfi-37)
  28. #:use-module (ice-9 match)
  29. #:use-module (ice-9 format)
  30. #:export (guix-import-cpan))
  31. ;;;
  32. ;;; Command-line options.
  33. ;;;
  34. (define %default-options
  35. '())
  36. (define (show-help)
  37. (display (G_ "Usage: guix import cpan PACKAGE-NAME
  38. Import and convert the CPAN package for PACKAGE-NAME.\n"))
  39. (display (G_ "
  40. -h, --help display this help and exit"))
  41. (display (G_ "
  42. -V, --version display version information and exit"))
  43. (newline)
  44. (show-bug-report-information))
  45. (define %options
  46. ;; Specification of the command-line options.
  47. (cons* (option '(#\h "help") #f #f
  48. (lambda args
  49. (show-help)
  50. (exit 0)))
  51. (option '(#\V "version") #f #f
  52. (lambda args
  53. (show-version-and-exit "guix import cpan")))
  54. %standard-import-options))
  55. ;;;
  56. ;;; Entry point.
  57. ;;;
  58. (define (guix-import-cpan . args)
  59. (define (parse-options)
  60. ;; Return the alist of option values.
  61. (parse-command-line args %options (list %default-options)
  62. #:build-options? #f))
  63. (let* ((opts (parse-options))
  64. (args (filter-map (match-lambda
  65. (('argument . value)
  66. value)
  67. (_ #f))
  68. (reverse opts))))
  69. (match args
  70. ((package-name)
  71. (let ((sexp (cpan->guix-package package-name)))
  72. (unless sexp
  73. (leave (G_ "failed to download meta-data for package '~a'~%")
  74. package-name))
  75. sexp))
  76. (()
  77. (leave (G_ "too few arguments~%")))
  78. ((many ...)
  79. (leave (G_ "too many arguments~%"))))))